polish_number 1.0.0 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.ruby-version +1 -1
- data/.travis.yml +1 -0
- data/README.md +2 -0
- data/lib/polish_number.rb +17 -4
- data/lib/polish_number/version.rb +1 -1
- data/spec/polish_number_spec.rb +8 -4
- metadata +3 -3
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 77827ce15243e32d648e16cd8a91289d3331e1c4
|
|
4
|
+
data.tar.gz: a110ec98a596daf35564e98353dae026e7ad8979
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 4c0a7e90298f992b71cbd6f20775bd069af83bb1d2dda1e4772fabbeaaacc3d79dff9e135c7b92c981d113bb919354e86e27815983489f1ba204850e6c3e03a7
|
|
7
|
+
data.tar.gz: e71e03fe8614bc9d554c9d5f829c2864db8e64a620941b0fdc0dfd5635bc976c6688d8c8a2a2eaf85ddf607027ce10ac8b440e93210672da4e8f0dfdea603e04
|
data/.ruby-version
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
2.1.
|
|
1
|
+
2.1.5
|
data/.travis.yml
CHANGED
data/README.md
CHANGED
|
@@ -33,3 +33,5 @@ Or install it yourself as:
|
|
|
33
33
|
3. Commit your changes (`git commit -am 'Add some feature'`)
|
|
34
34
|
4. Push to the branch (`git push origin my-new-feature`)
|
|
35
35
|
5. Create new Pull Request
|
|
36
|
+
|
|
37
|
+
[](https://github.com/igrigorik/ga-beacon)
|
data/lib/polish_number.rb
CHANGED
|
@@ -19,6 +19,8 @@ module PolishNumber
|
|
|
19
19
|
|
|
20
20
|
THOUSANDS = {:one => 'tysiąc', :few => 'tysiące', :many => 'tysięcy'}
|
|
21
21
|
|
|
22
|
+
MILLIONS = {:one => 'milion', :few => 'miliony', :many => 'milionów'}
|
|
23
|
+
|
|
22
24
|
CURRENCIES = {
|
|
23
25
|
:PLN => {:one => 'złoty', :few => 'złote', :many => 'złotych'}
|
|
24
26
|
}
|
|
@@ -30,21 +32,24 @@ module PolishNumber
|
|
|
30
32
|
|
|
31
33
|
number = number.to_i
|
|
32
34
|
|
|
33
|
-
unless (0..
|
|
34
|
-
raise ArgumentError, 'number should be in 0..
|
|
35
|
+
unless (0..999999999).include? number
|
|
36
|
+
raise ArgumentError, 'number should be in 0..999999999 range'
|
|
35
37
|
end
|
|
36
38
|
|
|
37
39
|
if number == 0
|
|
38
40
|
result = ZERO.dup
|
|
39
41
|
else
|
|
40
|
-
formatted_number = sprintf('%
|
|
42
|
+
formatted_number = sprintf('%09.0f', number)
|
|
41
43
|
digits = formatted_number.chars.map { |char| char.to_i }
|
|
42
44
|
|
|
43
45
|
result = ''
|
|
44
46
|
result << process_0_999(digits[0..2])
|
|
45
|
-
result <<
|
|
47
|
+
result << millions(number/1000000, digits[0..2])
|
|
46
48
|
result << ' '
|
|
47
49
|
result << process_0_999(digits[3..5])
|
|
50
|
+
result << thousands(number/1000, digits[3..5])
|
|
51
|
+
result << ' '
|
|
52
|
+
result << process_0_999(digits[6..9])
|
|
48
53
|
result.strip!
|
|
49
54
|
end
|
|
50
55
|
|
|
@@ -81,6 +86,14 @@ module PolishNumber
|
|
|
81
86
|
end
|
|
82
87
|
end
|
|
83
88
|
|
|
89
|
+
def self.millions(number, digits)
|
|
90
|
+
if number == 0
|
|
91
|
+
''
|
|
92
|
+
else
|
|
93
|
+
MILLIONS[classify(number, digits)]
|
|
94
|
+
end
|
|
95
|
+
end
|
|
96
|
+
|
|
84
97
|
def self.classify(number, digits)
|
|
85
98
|
if number == 1
|
|
86
99
|
:one
|
data/spec/polish_number_spec.rb
CHANGED
|
@@ -30,7 +30,9 @@ describe :PolishNumber do
|
|
|
30
30
|
10000 => 'dziesięć tysięcy',
|
|
31
31
|
22141 => 'dwadzieścia dwa tysiące sto czterdzieści jeden',
|
|
32
32
|
123754 => 'sto dwadzieścia trzy tysiące siedemset pięćdziesiąt cztery',
|
|
33
|
-
999999 => 'dziewięćset dziewięćdziesiąt dziewięć tysięcy dziewięćset dziewięćdziesiąt dziewięć'
|
|
33
|
+
999999 => 'dziewięćset dziewięćdziesiąt dziewięć tysięcy dziewięćset dziewięćdziesiąt dziewięć',
|
|
34
|
+
1999999 => 'jeden milion dziewięćset dziewięćdziesiąt dziewięć tysięcy dziewięćset dziewięćdziesiąt dziewięć',
|
|
35
|
+
5123754 => 'pięć milionów sto dwadzieścia trzy tysiące siedemset pięćdziesiąt cztery'
|
|
34
36
|
}.each do |number, translation|
|
|
35
37
|
it "should translate #{number} to '#{translation}'" do
|
|
36
38
|
PolishNumber.translate(number).should == translation
|
|
@@ -81,7 +83,9 @@ describe :PolishNumber do
|
|
|
81
83
|
10000 => 'dziesięć tysięcy złotych',
|
|
82
84
|
22141 => 'dwadzieścia dwa tysiące sto czterdzieści jeden złotych',
|
|
83
85
|
123754 => 'sto dwadzieścia trzy tysiące siedemset pięćdziesiąt cztery złote',
|
|
84
|
-
999999 => 'dziewięćset dziewięćdziesiąt dziewięć tysięcy dziewięćset dziewięćdziesiąt dziewięć złotych'
|
|
86
|
+
999999 => 'dziewięćset dziewięćdziesiąt dziewięć tysięcy dziewięćset dziewięćdziesiąt dziewięć złotych',
|
|
87
|
+
1999999 => 'jeden milion dziewięćset dziewięćdziesiąt dziewięć tysięcy dziewięćset dziewięćdziesiąt dziewięć złotych',
|
|
88
|
+
5123754 => 'pięć milionów sto dwadzieścia trzy tysiące siedemset pięćdziesiąt cztery złote'
|
|
85
89
|
}.each do |number, translation|
|
|
86
90
|
it "should translate #{number} to '#{translation}'" do
|
|
87
91
|
PolishNumber.translate(number, :currency => :PLN).should == translation
|
|
@@ -92,8 +96,8 @@ describe :PolishNumber do
|
|
|
92
96
|
lambda { PolishNumber.translate(-1) }.should.raise(ArgumentError)
|
|
93
97
|
end
|
|
94
98
|
|
|
95
|
-
it "should raise ArgumentError when number is greater than
|
|
96
|
-
lambda { PolishNumber.translate(
|
|
99
|
+
it "should raise ArgumentError when number is greater than 999999999.99" do
|
|
100
|
+
lambda { PolishNumber.translate(1_000_000_000) }.should.raise(ArgumentError)
|
|
97
101
|
end
|
|
98
102
|
|
|
99
103
|
it "should raise ArgumentError when currency is unknown" do
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: polish_number
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.
|
|
4
|
+
version: 1.1.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Wojciech Piekutowski
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2014-
|
|
11
|
+
date: 2014-12-16 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: bundler
|
|
@@ -107,7 +107,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
107
107
|
version: '0'
|
|
108
108
|
requirements: []
|
|
109
109
|
rubyforge_project:
|
|
110
|
-
rubygems_version: 2.
|
|
110
|
+
rubygems_version: 2.4.3
|
|
111
111
|
signing_key:
|
|
112
112
|
specification_version: 4
|
|
113
113
|
summary: Translates numbers to Polish words
|