papla 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,4 +1,8 @@
1
- ### 0.0.3 (2012-02-16)
1
+ ### 0.0.4 (2012-01-21)
2
+
3
+ * support English locale
4
+
5
+ ### 0.0.3 (2012-01-16)
2
6
 
3
7
  * provide localization using I18n
4
8
 
data/README.md CHANGED
@@ -1,6 +1,10 @@
1
1
  # Papla [![Build Status](https://secure.travis-ci.org/exviva/papla.png)](http://travis-ci.org/exviva/papla)
2
2
 
3
- Papla is a Ruby gem that allows you to convert numbers into Polish words (e.g. `153` into `"sto pięćdziesiąt trzy"`), including the decimal part as cents and currency symbol. Its primary use case are invoices, where the total amount has to be displayed as words at the bottom line.
3
+ Papla is a Ruby gem that allows you to convert numbers into Polish
4
+ and English words (e.g. `153` into `"Sto pięćdziesiąt trzy"`
5
+ or `44` into `"Forty four"`), including the decimal part as cents
6
+ and currency symbol. Its primary use case are invoices, where
7
+ the total amount has to be displayed as words at the bottom line.
4
8
 
5
9
  ## Installation
6
10
 
@@ -21,9 +25,13 @@ to your `Gemfile`.
21
25
  ### Basic examples
22
26
 
23
27
  ```ruby
28
+ I18n.locale = :pl
24
29
  Papla[158] # => "Sto pięćdziesiąt osiem"
25
30
  Papla[1_234] # => "Tysiąc dwieście trzydzieści cztery"
26
31
  Papla[987_654_321] # => "Dziewięćset osiemdziesiąt siedem milionów sześćset pięćdziesiąt cztery tysiące trzysta dwadzieścia jeden"
32
+
33
+ I18n.locale = :en
34
+ Papla[1_234] # => "One thousand two hundred thirty four"
27
35
  ```
28
36
 
29
37
  ### Cents and currency
@@ -50,7 +58,11 @@ This feature is planned for future releases.
50
58
 
51
59
  ### I18n
52
60
 
53
- Localization is provided by I18n. See `lib/papla/backend.rb` for details of keys used.
61
+ Localization is provided by I18n. See `lib/papla/backend.rb`
62
+ for details of keys used. Currently `:pl` and `:en` locales are supported.
63
+
64
+ Note: English support is not fully correct, e.g. `123` becomes
65
+ `"One hundred twenty three"` and not `"One hundred and twenty three"`.
54
66
 
55
67
  ### Money, Rails
56
68
 
@@ -2,8 +2,11 @@ require 'papla/backend'
2
2
  require 'papla/version'
3
3
 
4
4
  module Papla
5
- # Converts a number to Polish words, capitalizing
6
- # the first letter of the whole phrase.
5
+ # Converts a number to Polish or English words,
6
+ # capitalizing the first letter of the whole phrase.
7
+ #
8
+ # Localisation is provided by <tt>I18n</tt>, the language
9
+ # of the result depends on <tt>I18n.locale</tt>.
7
10
  #
8
11
  # Currently numbers from 0 up to 999 999 999
9
12
  # are supported. If you pass a bigger number,
@@ -15,6 +18,7 @@ module Papla
15
18
  #
16
19
  # Examples:
17
20
  #
21
+ # I18n.locale # => :pl
18
22
  # Papla[0] # => "Zero"
19
23
  # Papla[22] # => "Dwadzieścia dwa"
20
24
  # Papla[150] # => "Sto pięćdziesiąt"
@@ -35,7 +39,7 @@ module Papla
35
39
  # Papla[2.999] # => "Trzy 00/100"
36
40
  #
37
41
  # @param [Fixnum] number the number to convert
38
- # @return [String] the phrase in Polish
42
+ # @return [String] the phrase in Polish or English
39
43
  def self.[](number)
40
44
  validate!(number)
41
45
  number = prepare(number)
@@ -116,14 +120,8 @@ module Papla
116
120
  spell_cents(basic_phrase, cents)
117
121
  end
118
122
 
119
- @backends = {}
120
-
121
123
  def self.backend
122
- @backends[locale] ||= Backend.new(locale)
123
- end
124
-
125
- def self.locale
126
- :pl
124
+ @backend ||= Backend.new
127
125
  end
128
126
 
129
127
  def self.spell_zero; backend.zero; end
@@ -1,14 +1,9 @@
1
1
  require 'i18n'
2
2
 
3
- I18n.load_path << File.expand_path('../locale/pl.yml', __FILE__)
4
- I18n.load_path << File.expand_path('../locale/pl.rb', __FILE__)
3
+ I18n.load_path += Dir[File.expand_path('../locale/*', __FILE__)]
5
4
 
6
5
  module Papla
7
6
  class Backend
8
- def initialize(locale)
9
- @locale = locale
10
- end
11
-
12
7
  def zero
13
8
  translate(:zero)
14
9
  end
@@ -39,13 +34,12 @@ module Papla
39
34
  private
40
35
 
41
36
  def translate(message, options = {})
42
- options[:locale] = @locale
43
37
  options[:scope] = :papla
44
38
  I18n.translate(message, options)
45
39
  end
46
40
 
47
41
  def pluralization_rule(number)
48
- I18n.translate(:papla, locale: @locale)[:pluralization][number]
42
+ I18n.translate(:papla)[:pluralization][number]
49
43
  end
50
44
  end
51
45
  end
@@ -0,0 +1,9 @@
1
+ {
2
+ en: {
3
+ papla: {
4
+ pluralization: lambda do |n|
5
+ n == 1 ? :one : :other
6
+ end
7
+ }
8
+ }
9
+ }
@@ -0,0 +1,55 @@
1
+ en:
2
+ papla:
3
+ zero: zero
4
+ ones:
5
+ - ~
6
+ - one
7
+ - two
8
+ - three
9
+ - four
10
+ - five
11
+ - six
12
+ - seven
13
+ - eight
14
+ - nine
15
+ - ten
16
+ - eleven
17
+ - twelve
18
+ - thirteen
19
+ - fourteen
20
+ - fifteen
21
+ - sixteen
22
+ - seventeen
23
+ - eighteen
24
+ - nineteen
25
+ tens:
26
+ - ~
27
+ - ~
28
+ - twenty
29
+ - thirty
30
+ - forty
31
+ - fifty
32
+ - sixty
33
+ - seventy
34
+ - eighty
35
+ - ninety
36
+ hundreds:
37
+ - ~
38
+ - one hundred
39
+ - two hundred
40
+ - three hundred
41
+ - four hundred
42
+ - five hundred
43
+ - six hundred
44
+ - seven hundred
45
+ - eight hundred
46
+ - nine hundred
47
+ ranks:
48
+ - ~
49
+ -
50
+ one: thousand
51
+ other: thousand
52
+ -
53
+ one: million
54
+ other: million
55
+ cents: "%{basic_phrase} %{cents}/100"
@@ -54,8 +54,4 @@ pl:
54
54
  one: milion
55
55
  few: miliony
56
56
  other: milionów
57
- -
58
- one: miliard
59
- few: miliardy
60
- other: miliardów
61
57
  cents: "%{basic_phrase} %{cents}/100"
@@ -1,3 +1,3 @@
1
1
  module Papla
2
- VERSION = '0.0.3'
2
+ VERSION = '0.0.4'
3
3
  end
@@ -8,13 +8,13 @@ Gem::Specification.new do |s|
8
8
  s.authors = ["Olek Janiszewski"]
9
9
  s.email = ["olek.janiszewski@gmail.com"]
10
10
  s.homepage = "https://github.com/exviva/papla"
11
- s.summary = %q{Use Ruby to convert numbers into Polish words}
12
- s.description = %q{Papla is a Ruby gem that allows you to convert numbers into Polish words (e.g. 153 into "sto pięćdziesiąt trzy"), including the decimal part as cents and currency symbol. Its primary use case are invoices, where the total amount has to be displayed as words at the bottom line.}
11
+ s.summary = %q{Use Ruby to convert numbers into Polish and English words}
12
+ s.description = %q{Papla is a Ruby gem that allows you to convert numbers into Polish and English words (e.g. `153` into `"Sto pięćdziesiąt trzy"` or `44` into `"Forty four"`), including the decimal part as cents and currency symbol. Its primary use case are invoices, where the total amount has to be displayed as words at the bottom line.}
13
13
 
14
14
  s.rubyforge_project = "papla"
15
15
 
16
16
  s.files = `git ls-files`.split("\n")
17
- s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
17
+ s.test_files = `git ls-files -- {spec}/*`.split("\n")
18
18
  s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
19
19
  s.require_paths = ["lib"]
20
20
 
@@ -0,0 +1,235 @@
1
+ require 'spec_helper'
2
+
3
+ describe Papla, 'en' do
4
+ around do |example|
5
+ I18n.with_locale(:en) do
6
+ example.run
7
+ end
8
+ end
9
+
10
+ it 'converts basic numbers' do
11
+ subject[0].should eq('Zero')
12
+ subject[1].should eq('One')
13
+ subject[2].should eq('Two')
14
+ subject[3].should eq('Three')
15
+ subject[4].should eq('Four')
16
+ subject[5].should eq('Five')
17
+ subject[6].should eq('Six')
18
+ subject[7].should eq('Seven')
19
+ subject[8].should eq('Eight')
20
+ subject[9].should eq('Nine')
21
+ subject[10].should eq('Ten')
22
+ subject[11].should eq('Eleven')
23
+ subject[12].should eq('Twelve')
24
+ subject[13].should eq('Thirteen')
25
+ subject[14].should eq('Fourteen')
26
+ subject[15].should eq('Fifteen')
27
+ subject[16].should eq('Sixteen')
28
+ subject[17].should eq('Seventeen')
29
+ subject[18].should eq('Eighteen')
30
+ subject[19].should eq('Nineteen')
31
+ end
32
+
33
+ it 'joins number of tens and ones' do
34
+ subject[20].should eq('Twenty')
35
+ subject[21].should eq('Twenty one')
36
+ subject[30].should eq('Thirty')
37
+ subject[32].should eq('Thirty two')
38
+ subject[40].should eq('Forty')
39
+ subject[43].should eq('Forty three')
40
+ subject[50].should eq('Fifty')
41
+ subject[54].should eq('Fifty four')
42
+ subject[60].should eq('Sixty')
43
+ subject[65].should eq('Sixty five')
44
+ subject[70].should eq('Seventy')
45
+ subject[76].should eq('Seventy six')
46
+ subject[80].should eq('Eighty')
47
+ subject[87].should eq('Eighty seven')
48
+ subject[90].should eq('Ninety')
49
+ subject[98].should eq('Ninety eight')
50
+ end
51
+
52
+ it 'joins number of hundreds, tens and ones' do
53
+ subject[100].should eq('One hundred')
54
+ subject[101].should eq('One hundred one')
55
+ subject[111].should eq('One hundred eleven')
56
+ subject[122].should eq('One hundred twenty two')
57
+
58
+ subject[200].should eq('Two hundred')
59
+ subject[202].should eq('Two hundred two')
60
+ subject[212].should eq('Two hundred twelve')
61
+ subject[233].should eq('Two hundred thirty three')
62
+
63
+ subject[300].should eq('Three hundred')
64
+ subject[303].should eq('Three hundred three')
65
+ subject[313].should eq('Three hundred thirteen')
66
+ subject[344].should eq('Three hundred forty four')
67
+
68
+ subject[400].should eq('Four hundred')
69
+ subject[404].should eq('Four hundred four')
70
+ subject[414].should eq('Four hundred fourteen')
71
+ subject[455].should eq('Four hundred fifty five')
72
+
73
+ subject[500].should eq('Five hundred')
74
+ subject[505].should eq('Five hundred five')
75
+ subject[515].should eq('Five hundred fifteen')
76
+ subject[566].should eq('Five hundred sixty six')
77
+
78
+ subject[600].should eq('Six hundred')
79
+ subject[606].should eq('Six hundred six')
80
+ subject[616].should eq('Six hundred sixteen')
81
+ subject[677].should eq('Six hundred seventy seven')
82
+
83
+ subject[700].should eq('Seven hundred')
84
+ subject[707].should eq('Seven hundred seven')
85
+ subject[717].should eq('Seven hundred seventeen')
86
+ subject[788].should eq('Seven hundred eighty eight')
87
+
88
+ subject[800].should eq('Eight hundred')
89
+ subject[808].should eq('Eight hundred eight')
90
+ subject[818].should eq('Eight hundred eighteen')
91
+ subject[899].should eq('Eight hundred ninety nine')
92
+
93
+ subject[900].should eq('Nine hundred')
94
+ subject[909].should eq('Nine hundred nine')
95
+ subject[919].should eq('Nine hundred nineteen')
96
+ subject[990].should eq('Nine hundred ninety')
97
+ end
98
+
99
+ it 'supports thousands' do
100
+ subject[1000].should eq('One thousand')
101
+ subject[1001].should eq('One thousand one')
102
+ subject[1234].should eq('One thousand two hundred thirty four')
103
+ subject[1999].should eq('One thousand nine hundred ninety nine')
104
+
105
+ subject[2000].should eq('Two thousand')
106
+ subject[2001].should eq('Two thousand one')
107
+ subject[2345].should eq('Two thousand three hundred forty five')
108
+ subject[2888].should eq('Two thousand eight hundred eighty eight')
109
+
110
+ subject[3000].should eq('Three thousand')
111
+ subject[4000].should eq('Four thousand')
112
+ subject[5000].should eq('Five thousand')
113
+ subject[6000].should eq('Six thousand')
114
+ subject[7000].should eq('Seven thousand')
115
+ subject[8000].should eq('Eight thousand')
116
+ subject[9000].should eq('Nine thousand')
117
+ end
118
+
119
+ it 'supports tens of thousands' do
120
+ subject[10000].should eq('Ten thousand')
121
+
122
+ subject[11000].should eq('Eleven thousand')
123
+ subject[12000].should eq('Twelve thousand')
124
+ subject[13000].should eq('Thirteen thousand')
125
+ subject[14000].should eq('Fourteen thousand')
126
+ subject[15000].should eq('Fifteen thousand')
127
+ subject[16000].should eq('Sixteen thousand')
128
+ subject[17000].should eq('Seventeen thousand')
129
+ subject[18000].should eq('Eighteen thousand')
130
+ subject[19000].should eq('Nineteen thousand')
131
+ subject[20000].should eq('Twenty thousand')
132
+
133
+ subject[21000].should eq('Twenty one thousand')
134
+ subject[22000].should eq('Twenty two thousand')
135
+ subject[23000].should eq('Twenty three thousand')
136
+ subject[24000].should eq('Twenty four thousand')
137
+ subject[25000].should eq('Twenty five thousand')
138
+ subject[26000].should eq('Twenty six thousand')
139
+ subject[27000].should eq('Twenty seven thousand')
140
+ subject[28000].should eq('Twenty eight thousand')
141
+ subject[29000].should eq('Twenty nine thousand')
142
+
143
+ subject[33000].should eq('Thirty three thousand')
144
+ subject[44000].should eq('Forty four thousand')
145
+ subject[55000].should eq('Fifty five thousand')
146
+ subject[66000].should eq('Sixty six thousand')
147
+ subject[77000].should eq('Seventy seven thousand')
148
+ subject[88000].should eq('Eighty eight thousand')
149
+ subject[99000].should eq('Ninety nine thousand')
150
+ end
151
+
152
+ it 'supports hundreds of thousands' do
153
+ subject[100_000].should eq('One hundred thousand')
154
+
155
+ subject[101_000].should eq('One hundred one thousand')
156
+ subject[102_000].should eq('One hundred two thousand')
157
+ subject[103_000].should eq('One hundred three thousand')
158
+ subject[104_000].should eq('One hundred four thousand')
159
+ subject[105_000].should eq('One hundred five thousand')
160
+ subject[111_000].should eq('One hundred eleven thousand')
161
+ subject[112_000].should eq('One hundred twelve thousand')
162
+ subject[113_000].should eq('One hundred thirteen thousand')
163
+ subject[222_000].should eq('Two hundred twenty two thousand')
164
+ subject[333_000].should eq('Three hundred thirty three thousand')
165
+ subject[444_000].should eq('Four hundred forty four thousand')
166
+ subject[555_000].should eq('Five hundred fifty five thousand')
167
+ subject[666_000].should eq('Six hundred sixty six thousand')
168
+ subject[777_000].should eq('Seven hundred seventy seven thousand')
169
+ subject[999_000].should eq('Nine hundred ninety nine thousand')
170
+ subject[999_999].should eq('Nine hundred ninety nine thousand nine hundred ninety nine')
171
+ end
172
+
173
+ it 'supports millions' do
174
+ subject[1_000_000].should eq('One million')
175
+ subject[1_000_001].should eq('One million one')
176
+ subject[1_001_001].should eq('One million one thousand one')
177
+ subject[1_234_567].should eq('One million two hundred thirty four thousand five hundred sixty seven')
178
+ subject[2_000_000].should eq('Two million')
179
+ subject[3_303_303].should eq('Three million three hundred three thousand three hundred three')
180
+ subject[4_004_000].should eq('Four million four thousand')
181
+ subject[5_500_000].should eq('Five million five hundred thousand')
182
+ subject[6_000_000].should eq('Six million')
183
+ subject[7_000_000].should eq('Seven million')
184
+ subject[9_000_000].should eq('Nine million')
185
+ end
186
+
187
+ it 'supports tens of millions' do
188
+ subject[11_000_000].should eq('Eleven million')
189
+ subject[13_000_000].should eq('Thirteen million')
190
+ subject[15_000_000].should eq('Fifteen million')
191
+ subject[19_000_000].should eq('Nineteen million')
192
+ subject[20_000_000].should eq('Twenty million')
193
+ subject[22_000_000].should eq('Twenty two million')
194
+ subject[33_000_000].should eq('Thirty three million')
195
+ subject[44_000_000].should eq('Forty four million')
196
+ subject[55_000_000].should eq('Fifty five million')
197
+ subject[66_000_000].should eq('Sixty six million')
198
+ subject[77_000_000].should eq('Seventy seven million')
199
+ subject[88_000_000].should eq('Eighty eight million')
200
+ subject[99_000_000].should eq('Ninety nine million')
201
+ subject[99_999_999].should eq('Ninety nine million nine hundred ninety nine thousand nine hundred ninety nine')
202
+ end
203
+
204
+ it 'supports hundreds of millions' do
205
+ subject[100_000_000].should eq('One hundred million')
206
+ subject[100_000_001].should eq('One hundred million one')
207
+ subject[102_100_000].should eq('One hundred two million one hundred thousand')
208
+ subject[222_000_000].should eq('Two hundred twenty two million')
209
+ subject[333_000_000].should eq('Three hundred thirty three million')
210
+ subject[400_000_000].should eq('Four hundred million')
211
+ subject[500_000_000].should eq('Five hundred million')
212
+ subject[600_000_000].should eq('Six hundred million')
213
+ subject[700_000_000].should eq('Seven hundred million')
214
+ subject[880_000_000].should eq('Eight hundred eighty million')
215
+ subject[999_999_999].should eq('Nine hundred ninety nine million nine hundred ninety nine thousand nine hundred ninety nine')
216
+ end
217
+
218
+ it 'does not support billions' do
219
+ expect { subject[1_000_000_000] }.to raise_error(ArgumentError)
220
+ end
221
+
222
+ describe 'floats' do
223
+ it 'appends the decimal part as cents' do
224
+ subject[1.23].should eq('One 23/100')
225
+ end
226
+
227
+ it 'displays two decimal digits' do
228
+ subject[2.0].should eq('Two 00/100')
229
+ end
230
+
231
+ it 'rounds to two decimal places' do
232
+ subject[3.456].should eq('Three 46/100')
233
+ end
234
+ end
235
+ end
@@ -1,7 +1,13 @@
1
1
  # encoding: utf-8
2
2
  require 'spec_helper'
3
3
 
4
- describe Papla do
4
+ describe Papla, 'pl' do
5
+ around do |example|
6
+ I18n.with_locale(:pl) do
7
+ example.run
8
+ end
9
+ end
10
+
5
11
  it 'converts basic numbers' do
6
12
  subject[0].should eq('Zero')
7
13
  subject[1].should eq('Jeden')
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: papla
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-01-16 00:00:00.000000000 Z
12
+ date: 2012-01-21 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: i18n
16
- requirement: &6025320 !ruby/object:Gem::Requirement
16
+ requirement: &16305740 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *6025320
24
+ version_requirements: *16305740
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: rspec
27
- requirement: &6023880 !ruby/object:Gem::Requirement
27
+ requirement: &16304540 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: 2.8.0
33
33
  type: :development
34
34
  prerelease: false
35
- version_requirements: *6023880
35
+ version_requirements: *16304540
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: rake
38
- requirement: &6021540 !ruby/object:Gem::Requirement
38
+ requirement: &16302140 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,11 +43,11 @@ dependencies:
43
43
  version: '0'
44
44
  type: :development
45
45
  prerelease: false
46
- version_requirements: *6021540
47
- description: Papla is a Ruby gem that allows you to convert numbers into Polish words
48
- (e.g. 153 into "sto pięćdziesiąt trzy"), including the decimal part as cents and
49
- currency symbol. Its primary use case are invoices, where the total amount has to
50
- be displayed as words at the bottom line.
46
+ version_requirements: *16302140
47
+ description: Papla is a Ruby gem that allows you to convert numbers into Polish and
48
+ English words (e.g. `153` into `"Sto pięćdziesiąt trzy"` or `44` into `"Forty four"`),
49
+ including the decimal part as cents and currency symbol. Its primary use case are
50
+ invoices, where the total amount has to be displayed as words at the bottom line.
51
51
  email:
52
52
  - olek.janiszewski@gmail.com
53
53
  executables: []
@@ -64,11 +64,14 @@ files:
64
64
  - Rakefile
65
65
  - lib/papla.rb
66
66
  - lib/papla/backend.rb
67
+ - lib/papla/locale/en.rb
68
+ - lib/papla/locale/en.yml
67
69
  - lib/papla/locale/pl.rb
68
70
  - lib/papla/locale/pl.yml
69
71
  - lib/papla/version.rb
70
72
  - papla.gemspec
71
- - spec/papla_spec.rb
73
+ - spec/en_spec.rb
74
+ - spec/pl_spec.rb
72
75
  - spec/spec_helper.rb
73
76
  homepage: https://github.com/exviva/papla
74
77
  licenses: []
@@ -93,5 +96,5 @@ rubyforge_project: papla
93
96
  rubygems_version: 1.8.10
94
97
  signing_key:
95
98
  specification_version: 3
96
- summary: Use Ruby to convert numbers into Polish words
99
+ summary: Use Ruby to convert numbers into Polish and English words
97
100
  test_files: []