ka 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: d30a8c7f424c03955bafdd2d3e924c99f3b19e7d
4
+ data.tar.gz: e72d3226c243a6ca0c098951219d410f8e76241e
5
+ SHA512:
6
+ metadata.gz: 3231301d0f0dd95e7a27589159e2e255da2802c64df8b166088bfbc0c67fe645e3185ea33c291481863fa906255147cf2b7c224ff808bbf483d6ce9843930187
7
+ data.tar.gz: 16dc3cf917935a9fb1a364b1ebc7944c4d33f63c0898cb3d9c07cb2979b8002cee34665d3529f28393ffa7a3f1dfa3ec2b62731f4b3ccad31c1046390c3358fb
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in ka.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Dimitri Kurashvili
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,82 @@
1
+ # KA: write georgian sofwate with ruby
2
+
3
+ There are number of occasions when you deal with uncommon situations in georgian software.
4
+ Those are:
5
+
6
+ * mobile number validation,
7
+ * numbers to readable format (1 -> 'ერთი'),
8
+ * date formatting (not supported by i18n)
9
+ * and outdated, but still active, GEO character encoding.
10
+
11
+ KA gem will enable you to deal with all these situations.
12
+
13
+ ## Installation
14
+
15
+ Add this line to your application's Gemfile:
16
+
17
+ gem 'ka',
18
+
19
+ And then execute:
20
+
21
+ $ bundle
22
+
23
+ Or install it yourself as:
24
+
25
+ $ gem install ka
26
+
27
+ ## Usage
28
+
29
+ ### Mobile numbers
30
+
31
+ Validation and formatting of mobile numbers are self-exmplanatory:
32
+
33
+ ```ruby
34
+ require 'ka'
35
+ include KA
36
+ ...
37
+ mobile = 'my mobile: (595) 33 55 14'
38
+ compact_mobile(mobile) # => '595335514'
39
+ correct_mobile?(mobile) # => true
40
+ format_mobile(mobile, operator_pre: '[', operator_suf: ']', by: 2, separator: ' ') #=> [595]33 55 14
41
+ ```
42
+
43
+ ### Number spelling
44
+
45
+ `to_ka` method is integrated within `Integer` class.
46
+ Now you can convert integers into georgian words (works upto 999,999,999,999,999).
47
+
48
+ This task is often, especialy when writing some accounting software.
49
+
50
+ ```ruby
51
+ 1.to_ka # => ერთი
52
+ 999_999_999_999_999.to_ka # => ცხრაას ოთხმოცდა ცხრამეტი ტრილიონ ცხრაას ოთხმოცდა ცხრამეტი მილიარდ ცხრაას ოთხმოცდა ცხრამეტი მილიონ ცხრაას ოთხმოცდა ცხრამეტი ათას ცხრაას ოთხმოცდა ცხრამეტი
53
+ ```
54
+
55
+ ### Date formats
56
+
57
+ TODO:
58
+
59
+ ### GEO character encoding
60
+
61
+ When using the `ka` gem `String` automatically receives the `to_ka`, `to_geo` and `to_lat` methods.
62
+
63
+ ```ruby
64
+ 'dimitri'.to_ka(:all) # => დიმიტრი
65
+ 'დიმიტრი'.to_lat # => dimitri
66
+ 'დიმიტრი'.to_geo # => ÃÉÌÉÔÒÉ
67
+ ```
68
+
69
+ The `to_ka` method receives the additional `type` parameter which indicates which characters
70
+ to use when converting to georgian unicode. There are three possible values for this parameter:
71
+
72
+ * `geo`, convert only GEO characters (default),
73
+ * `lat`, convert only LAT characters and
74
+ * `all`, converts both GEO and LAT characters.
75
+
76
+ ## Contributing
77
+
78
+ 1. Fork it
79
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
80
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
81
+ 4. Push to the branch (`git push origin my-new-feature`)
82
+ 5. Create new Pull Request
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,24 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'ka/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "ka"
8
+ spec.version = Ka::VERSION
9
+ spec.authors = ["Dimitri Kurashvili"]
10
+ spec.email = ["dimakura@gmail.com"]
11
+ spec.description = %q{georgian language functionality}
12
+ spec.summary = %q{common functionality for georgian language software}
13
+ spec.homepage = "http://carbon.ge"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency 'bundler', '~> 1.3'
22
+ spec.add_development_dependency 'rake'
23
+ spec.add_development_dependency 'rspec', '~> 2'
24
+ end
@@ -0,0 +1,5 @@
1
+ # -*- encoding : utf-8 -*-
2
+ require 'ka/version'
3
+ require 'ka/mobile'
4
+ require 'ka/string'
5
+ require 'ka/integer'
@@ -0,0 +1,98 @@
1
+ # -*- encoding : utf-8 -*-
2
+
3
+ class Integer
4
+
5
+ def to_ka
6
+ if self < 0
7
+ "მინუს #{tokenize_int_ge_0(-self)}"
8
+ else
9
+ tokenize_int_ge_0(self)
10
+ end
11
+ end
12
+
13
+ private
14
+
15
+ def tokenize_int_ge_0(num)
16
+ case num
17
+ when 0 then return 'ნული'
18
+ when 1 then return 'ერთი'
19
+ when 2 then return 'ორი'
20
+ when 3 then return 'სამი'
21
+ when 4 then return 'ოთხი'
22
+ when 5 then return 'ხუთი'
23
+ when 6 then return 'ექვსი'
24
+ when 7 then return 'შვიდი'
25
+ when 8 then return 'რვა'
26
+ when 9 then return 'ცხრა'
27
+ when 10 then return 'ათი'
28
+ when 11 then return 'თერთმეტი'
29
+ when 12 then return 'თორმეტი'
30
+ when 13 then return 'ცამეტი'
31
+ when 14 then return 'თოთხმეტი'
32
+ when 15 then return 'თხუთმეტი'
33
+ when 16 then return 'თექვსმეტი'
34
+ when 17 then return 'ჩვიდმეტი'
35
+ when 18 then return 'თვრამეტი'
36
+ when 19 then return 'ცხრამეტი'
37
+ when 20 then return 'ოცი'
38
+ when 40 then return 'ორმოცი'
39
+ when 60 then return 'სამოცი'
40
+ when 80 then return 'ოთხმოცი'
41
+ when 100 then return 'ასი'
42
+ when 200 then return 'ორასი'
43
+ when 300 then return 'სამასი'
44
+ when 400 then return 'ოთხასი'
45
+ when 500 then return 'ხუთასი'
46
+ when 600 then return 'ექვსასი'
47
+ when 700 then return 'შვიდასი'
48
+ when 800 then return 'რვაასი'
49
+ when 900 then return 'ცხრაასი'
50
+ when 1000 then return 'ათასი'
51
+ when 1000000 then return 'მილიონი'
52
+ when 1000000000 then return 'მილიარდი'
53
+ when 1000000000000 then return 'ტრილიონი'
54
+ #else '???'
55
+ end
56
+ return "ოცდა #{tokenize_int_ge_0(num-20)}" if num > 20 and num < 40
57
+ return "ორმოცდა #{tokenize_int_ge_0(num-40)}" if num > 40 and num < 60
58
+ return "სამოცდა #{tokenize_int_ge_0(num-60)}" if num > 60 and num < 80
59
+ return "ოთხმოცდა #{tokenize_int_ge_0(num-80)}" if num > 80 and num < 100
60
+ return "ას #{tokenize_int_ge_0(num-100)}" if num > 100 and num < 200
61
+ return "ორას #{tokenize_int_ge_0(num-200)}" if num > 200 and num < 300
62
+ return "სამას #{tokenize_int_ge_0(num-300)}" if num > 300 and num < 400
63
+ return "ოთხას #{tokenize_int_ge_0(num-400)}" if num > 400 and num < 500
64
+ return "ხუთას #{tokenize_int_ge_0(num-500)}" if num > 500 and num < 600
65
+ return "ექვსას #{tokenize_int_ge_0(num-600)}" if num > 600 and num < 700
66
+ return "შვიდას #{tokenize_int_ge_0(num-700)}" if num > 700 and num < 800
67
+ return "რვაას #{tokenize_int_ge_0(num-800)}" if num > 800 and num < 900
68
+ return "ცხრაას #{tokenize_int_ge_0(num-900)}" if num > 900 and num < 1000
69
+ return "ათას #{tokenize_int_ge_0(num-1000)}" if num > 1000 and num < 2000
70
+ if num >= 2000 and num <= 999999
71
+ thousands = num/1000
72
+ rest = num - thousands * 1000
73
+ return "#{tokenize_int_ge_0(thousands)} ათას #{tokenize_int_ge_0(rest)}" if rest != 0
74
+ return "#{tokenize_int_ge_0(thousands)} ათასი" if rest == 0
75
+ end
76
+ return "მილიონ #{tokenize_int_ge_0(num-1000000)}" if num > 1000000 and num < 2000000
77
+ if num >= 2000000 and num <= 999999999
78
+ millions = num/1000000
79
+ rest = num - millions * 1000000
80
+ return "#{tokenize_int_ge_0(millions)} მილიონ #{tokenize_int_ge_0(rest)}" if rest != 0
81
+ return "#{tokenize_int_ge_0(millions)} მილიონი" if rest == 0
82
+ end
83
+ return "მილიარდ #{tokenize_int_ge_0(num-1000000000)}" if num > 1000000000 and num < 2000000000
84
+ if num >= 2000000000 and num <= 999999999999
85
+ billions = num/1000000000
86
+ rest = num - billions * 1000000000
87
+ return "#{tokenize_int_ge_0(billions)} მილიარდ #{tokenize_int_ge_0(rest)}" if rest != 0
88
+ return "#{tokenize_int_ge_0(billions)} მილიარდი"
89
+ end
90
+ if num >= 2000000000000 and num <= 999999999999999
91
+ billions = num/1000000000000
92
+ rest = num - billions * 1000000000000
93
+ return "#{tokenize_int_ge_0(billions)} ტრილიონ #{tokenize_int_ge_0(rest)}" if rest != 0
94
+ return "#{tokenize_int_ge_0(billions)} ტრილიონი"
95
+ end
96
+ return num.to_s
97
+ end
98
+ end
@@ -0,0 +1,41 @@
1
+ # -*- encoding : utf-8 -*-
2
+ module KA
3
+
4
+ # Compacts mobile number, throwing out all non-digit characters.
5
+ def compact_mobile(mob)
6
+ mob.scan(/[0-9]/).join('') if mob
7
+ end
8
+
9
+ # Correct mobiles are those which are 9 digits after compaction and start with the digit '5'.
10
+ def correct_mobile?(mob)
11
+ compacted = compact_mobile(mob)
12
+ (not not (compacted =~ /^[0-9]{9}$/)) and (compacted[0] == '5')
13
+ end
14
+
15
+ # Formats mobile number.
16
+ #
17
+ # The default implementation is format mobile as `(XXX)XXX-XXX`, where `X` denotes a digit.
18
+ #
19
+ # You can specify the different format using formatting options:
20
+ #
21
+ # ```
22
+ # mob = format_mobile('595335514', operator_pre: '[', operator_suf: ']', by: 2, separator: ' ')
23
+ # # => [595]33 55 14
24
+ # ```
25
+ def format_mobile(mob, h = {})
26
+ operator_pre = h[:operator_pre] || h['operator_pre'] || '('
27
+ operator_suf = h[:operator_suf] || h['operator_suf'] || ')'
28
+ by = h[:by] || h['by'] || 3
29
+ separator = h[:separator] || h['separator'] || '-'
30
+ mob = compact_mobile(mob)
31
+ operator = mob[0..2]
32
+ digits = mob[3..8].scan(/.{1,#{by}}/)
33
+ [operator_pre, operator, operator_suf, digits.join(separator)].join('')
34
+ #"(#{operator})#{mob[3..5]}-#{mob[6..8]}"
35
+ end
36
+
37
+ module_function :compact_mobile
38
+ module_function :correct_mobile?
39
+ module_function :format_mobile
40
+
41
+ end
@@ -0,0 +1,53 @@
1
+ # -*- encoding : utf-8 -*-
2
+ class String
3
+
4
+ # # Generates next numeric value from this string.
5
+ # def next_number
6
+ # index = self.index(/[0-9]*$/)
7
+ # if index
8
+ # pref = self[0, index]
9
+ # suff = self[index, self.length].to_i + 1
10
+ # lnth = self.length - pref.length
11
+ # %Q{#{pref}#{("%0#{lnth}d" % suff)}}
12
+ # else
13
+ # "#{self}1"
14
+ # end
15
+ # end
16
+
17
+ # Translation between legacy character sets.
18
+
19
+ GEO = 'ÀÁÂÃÄÅÆÈÉÊËÌÍÏÐÑÒÓÔÖ×ØÙÚÛÜÝÞßàáãä'
20
+ KA = 'აბგდევზთიკლმნოპჟრსტუფქღყშჩცძწჭხჯჰ'
21
+ LAT = 'abgdevzTiklmnopJrstufqRySCcZwWxjh'
22
+
23
+ def translate(from, to)
24
+ txt = ""
25
+ self.split('').each do |c|
26
+ indx = from.index(c)
27
+ txt << (indx ? to[indx] : c)
28
+ end
29
+ txt
30
+ end
31
+
32
+ # Translates this string into true georgian unicode symbols.
33
+ # Use `type` paramter to specify which type of conversion to use.
34
+ # Possible values for this parameters are `geo` (default), `lat` and `all`.
35
+ def to_ka(type = 'geo')
36
+ case type.to_s
37
+ when 'all' then self.translate("#{GEO}#{LAT}", "#{KA}#{KA}")
38
+ when 'lat' then self.translate(LAT, KA)
39
+ else self.translate(GEO, KA)
40
+ end
41
+ end
42
+
43
+ # Translates georgian into GEO encoding.
44
+ def to_geo
45
+ self.translate(KA, GEO)
46
+ end
47
+
48
+ # Translates georgian into LAT encoding.
49
+ def to_lat
50
+ self.translate("#{GEO}#{KA}", "#{LAT}#{LAT}")
51
+ end
52
+
53
+ end
@@ -0,0 +1,4 @@
1
+ # -*- encoding : utf-8 -*-
2
+ module Ka
3
+ VERSION = "0.1.0"
4
+ end
@@ -0,0 +1,15 @@
1
+ # -*- encoding : utf-8 -*-
2
+ require 'spec_helper'
3
+
4
+ describe 'integer into text' do
5
+ specify { 1.to_ka.should == 'ერთი' }
6
+ specify { 2.to_ka.should == 'ორი' }
7
+ specify { 20.to_ka.should == 'ოცი' }
8
+ specify { 25.to_ka.should == 'ოცდა ხუთი' }
9
+ specify { 1234.to_ka.should == 'ათას ორას ოცდა თოთხმეტი' }
10
+ specify { 1000_000.to_ka.should == 'მილიონი' }
11
+ specify { 1000_000_000.to_ka.should == 'მილიარდი' }
12
+ specify { 1000_000_000_000.to_ka.should == 'ტრილიონი' }
13
+ specify { 999.to_ka.should == 'ცხრაას ოთხმოცდა ცხრამეტი' }
14
+ specify { 999_999_999_999_999.to_ka.should == 'ცხრაას ოთხმოცდა ცხრამეტი ტრილიონ ცხრაას ოთხმოცდა ცხრამეტი მილიარდ ცხრაას ოთხმოცდა ცხრამეტი მილიონ ცხრაას ოთხმოცდა ცხრამეტი ათას ცხრაას ოთხმოცდა ცხრამეტი' }
15
+ end
@@ -0,0 +1,28 @@
1
+ # -*- encoding : utf-8 -*-
2
+ require 'spec_helper'
3
+ include KA
4
+
5
+ describe "mobile correctness" do
6
+ specify { correct_mobile?('595335514').should == true }
7
+ specify { correct_mobile?('(595)33-55-14').should == true }
8
+ specify { correct_mobile?('(595)335-514').should == true }
9
+ specify { correct_mobile?('mob: (595)335-514').should == true }
10
+ specify { correct_mobile?('mob: (895)335-514').should == false }
11
+ specify { correct_mobile?('mob: (595)335-51').should == false }
12
+ specify { correct_mobile?('mob: (595)335-5144').should == false }
13
+ end
14
+
15
+ describe "compacting mobile" do
16
+ specify { compact_mobile('595335514').should == '595335514' }
17
+ specify { compact_mobile('(595)335514').should == '595335514' }
18
+ specify { compact_mobile('(595)335-514').should == '595335514' }
19
+ specify { compact_mobile('mob: (595)335514').should == '595335514' }
20
+ end
21
+
22
+ describe "format mobile" do
23
+ specify { format_mobile('595335514').should == '(595)335-514' }
24
+ specify { format_mobile('(595)335514').should == '(595)335-514' }
25
+ specify { format_mobile('mob: (595)335514').should == '(595)335-514' }
26
+ specify { format_mobile('595335514', by: 1, operator_pre: '[', operator_suf: ']').should == '[595]3-3-5-5-1-4' }
27
+ specify { format_mobile('595335514', by: 2, separator: ' ').should == '(595)33 55 14' }
28
+ end
@@ -0,0 +1,7 @@
1
+ # -*- encoding : utf-8 -*-
2
+ require 'rspec'
3
+ require 'ka'
4
+
5
+ RSpec.configure do |config|
6
+ config.include(RSpec::Matchers)
7
+ end
@@ -0,0 +1,8 @@
1
+ # -*- encoding : utf-8 -*-
2
+ require 'spec_helper'
3
+
4
+ describe 'conversion' do
5
+ specify { 'dimitri'.to_ka(:all).should == 'დიმიტრი' }
6
+ specify { 'დიმიტრი'.to_lat.should == 'dimitri' }
7
+ specify { 'დიმიტრი'.to_geo.should == 'ÃÉÌÉÔÒÉ' }
8
+ end
metadata ADDED
@@ -0,0 +1,106 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ka
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Dimitri Kurashvili
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-05-06 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '1.3'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ~>
46
+ - !ruby/object:Gem::Version
47
+ version: '2'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: '2'
55
+ description: georgian language functionality
56
+ email:
57
+ - dimakura@gmail.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - .gitignore
63
+ - .rspec
64
+ - Gemfile
65
+ - LICENSE.txt
66
+ - README.md
67
+ - Rakefile
68
+ - ka.gemspec
69
+ - lib/ka.rb
70
+ - lib/ka/integer.rb
71
+ - lib/ka/mobile.rb
72
+ - lib/ka/string.rb
73
+ - lib/ka/version.rb
74
+ - spec/integer_spec.rb
75
+ - spec/mobile_spec.rb
76
+ - spec/spec_helper.rb
77
+ - spec/string_spec.rb
78
+ homepage: http://carbon.ge
79
+ licenses:
80
+ - MIT
81
+ metadata: {}
82
+ post_install_message:
83
+ rdoc_options: []
84
+ require_paths:
85
+ - lib
86
+ required_ruby_version: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - '>='
89
+ - !ruby/object:Gem::Version
90
+ version: '0'
91
+ required_rubygems_version: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - '>='
94
+ - !ruby/object:Gem::Version
95
+ version: '0'
96
+ requirements: []
97
+ rubyforge_project:
98
+ rubygems_version: 2.0.3
99
+ signing_key:
100
+ specification_version: 4
101
+ summary: common functionality for georgian language software
102
+ test_files:
103
+ - spec/integer_spec.rb
104
+ - spec/mobile_spec.rb
105
+ - spec/spec_helper.rb
106
+ - spec/string_spec.rb