spell_number 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ features/**/*.feature
5
+ LICENSE.txt
data/Gemfile ADDED
@@ -0,0 +1,14 @@
1
+ source "http://rubygems.org"
2
+ # Add dependencies required to use your gem here.
3
+ # Example:
4
+ # gem "activesupport", ">= 2.3.5"
5
+ gem "i18n", ">= 0.3.7"
6
+
7
+ # Add dependencies to develop your gem here.
8
+ # Include everything needed to run rake, tests, features, etc.
9
+ group :development do
10
+ gem "rspec", "~> 2.3.0"
11
+ gem "bundler", "~> 1.0.0"
12
+ gem "jeweler", "~> 1.5.2"
13
+ gem "rcov", ">= 0"
14
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,30 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ diff-lcs (1.1.2)
5
+ git (1.2.5)
6
+ i18n (0.5.0)
7
+ jeweler (1.5.2)
8
+ bundler (~> 1.0.0)
9
+ git (>= 1.2.5)
10
+ rake
11
+ rake (0.8.7)
12
+ rcov (0.9.9)
13
+ rspec (2.3.0)
14
+ rspec-core (~> 2.3.0)
15
+ rspec-expectations (~> 2.3.0)
16
+ rspec-mocks (~> 2.3.0)
17
+ rspec-core (2.3.1)
18
+ rspec-expectations (2.3.0)
19
+ diff-lcs (~> 1.1.2)
20
+ rspec-mocks (2.3.0)
21
+
22
+ PLATFORMS
23
+ ruby
24
+
25
+ DEPENDENCIES
26
+ bundler (~> 1.0.0)
27
+ i18n (>= 0.3.7)
28
+ jeweler (~> 1.5.2)
29
+ rcov
30
+ rspec (~> 2.3.0)
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ Copyright (c) 2011 gut.org gAG (betterplace.org)
2
+ Author: Daniel Hahn
3
+
4
+ Permission is hereby granted, free of charge, to any person obtaining
5
+ a copy of this software and associated documentation files (the
6
+ "Software"), to deal in the Software without restriction, including
7
+ without limitation the rights to use, copy, modify, merge, publish,
8
+ distribute, sublicense, and/or sell copies of the Software, and to
9
+ permit persons to whom the Software is furnished to do so, subject to
10
+ the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be
13
+ included in all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
19
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
20
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,32 @@
1
+ = spell_number
2
+
3
+ This is a simple gem that will allow you to convert numbers into a "written" representation. E.g. 111 becomes "onehundredeleven"
4
+
5
+ == Known limitations
6
+
7
+ * The code can still be DRYed up
8
+ * At the moment, the code will only handle German and English. Other languages can be added through I18n locale files, but may
9
+ need additional tweaking for edge cases.
10
+
11
+
12
+ == Usage
13
+
14
+ At the moment, just add the gem to your Gemfile, and then do
15
+
16
+ SpellNumber.number_to_words(number, :locale => my_locale)
17
+
18
+ == Contributing to spell_number
19
+
20
+ * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
21
+ * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
22
+ * Fork the project
23
+ * Start a feature/bugfix branch
24
+ * Commit and push until you are happy with your contribution
25
+ * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
26
+ * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
27
+
28
+ == Copyright
29
+
30
+ Copyright (c) 2011 Daniel Hahn. See LICENSE.txt for
31
+ further details.
32
+
data/Rakefile ADDED
@@ -0,0 +1,50 @@
1
+ require 'rubygems'
2
+ require 'bundler'
3
+ begin
4
+ Bundler.setup(:default, :development)
5
+ rescue Bundler::BundlerError => e
6
+ $stderr.puts e.message
7
+ $stderr.puts "Run `bundle install` to install missing gems"
8
+ exit e.status_code
9
+ end
10
+ require 'rake'
11
+
12
+ require 'jeweler'
13
+ Jeweler::Tasks.new do |gem|
14
+ # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
15
+ gem.name = "spell_number"
16
+ gem.homepage = "http://github.com/betterplace/spell_number"
17
+ gem.license = "MIT"
18
+ gem.summary = "Spell numbers as words"
19
+ gem.description = "Simple Gem to spell numbers as words"
20
+ gem.email = "developers@betterplace.org"
21
+ gem.authors = ["Daniel Hahn"]
22
+ # Include your dependencies below. Runtime dependencies are required when using your gem,
23
+ # and development dependencies are only needed for development (ie running rake tasks, tests, etc)
24
+ # gem.add_runtime_dependency 'jabber4r', '> 0.1'
25
+ # gem.add_development_dependency 'rspec', '> 1.2.3'
26
+ end
27
+ Jeweler::RubygemsDotOrgTasks.new
28
+
29
+ require 'rspec/core/rake_task'
30
+ desc "Run all examples"
31
+ RSpec::Core::RakeTask.new(:spec)
32
+
33
+ require 'rcov/rcovtask'
34
+ Rcov::RcovTask.new do |test|
35
+ test.libs << 'rspec'
36
+ test.pattern = 'spec/**/*_spec.rb'
37
+ test.verbose = true
38
+ end
39
+
40
+ task :default => :test
41
+
42
+ require 'rake/rdoctask'
43
+ Rake::RDocTask.new do |rdoc|
44
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
45
+
46
+ rdoc.rdoc_dir = 'rdoc'
47
+ rdoc.title = "spell_number #{version}"
48
+ rdoc.rdoc_files.include('README*')
49
+ rdoc.rdoc_files.include('lib/**/*.rb')
50
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.0.1
@@ -0,0 +1,91 @@
1
+ module SpellNumber
2
+
3
+ class Speller
4
+
5
+ def initialize(options = {})
6
+ @options = options
7
+ end
8
+
9
+ def number_to_words(number)
10
+ return number_with_thousands(number) if(number < 1000000)
11
+
12
+ rest = number % 1000000
13
+
14
+ singular = ((number / 1000000) == 1)
15
+ millions = number_with_thousands(number / 1000000)
16
+ rest_in_words = number_with_thousands(rest)
17
+ words = 'not_found'
18
+
19
+ words = I18n.t("spell_number.formats.millions_singular.#{format_subtype(rest)}", :locale => @options[:locale],
20
+ :million_count => millions, :rest => rest_in_words, :default => 'not_found') if(singular)
21
+
22
+ words = I18n.t("spell_number.formats.millions.#{format_subtype(rest)}", :locale => @options[:locale],
23
+ :million_count => millions, :rest => rest_in_words) if(words == 'not_found')
24
+
25
+ words
26
+ end
27
+
28
+ protected
29
+
30
+ def number_with_thousands(number, combined = false)
31
+ return three_digit_number(number, combined) if(number < 1000)
32
+
33
+ rest = number % 1000
34
+
35
+ thousands = three_digit_number(number / 1000, true)
36
+ rest_in_words = three_digit_number(rest)
37
+ I18n.t("spell_number.formats.thousands.#{format_subtype(rest)}", :locale => @options[:locale],
38
+ :thousand_count => thousands, :rest => rest_in_words)
39
+ end
40
+
41
+ def three_digit_number(number, combined = false)
42
+ if(number < 100)
43
+ two_digit_number(number, combined)
44
+ else
45
+ rest = number % 100
46
+ format = "spell_number.formats.hundreds.#{rest == 0 ? 'no_rest' : 'rest'}"
47
+ hundreds = simple_number_to_words_combined(number / 100)
48
+ rest = two_digit_number(rest)
49
+ I18n.t(format, :locale => @options[:locale], :hundred_count => hundreds, :rest => rest)
50
+ end
51
+ end
52
+
53
+ # Transforms a two-digit number from 0 to 99
54
+ def two_digit_number(number, combined = false)
55
+ words = combined ? simple_number_to_words_combined(number) : simple_number_to_words(number)
56
+ return words if(words != 'not_found')
57
+
58
+ rest = number % 10
59
+ format = "spell_number.formats.tens.#{rest == 0 ? 'no_rest' : 'rest'}"
60
+ first_digit = simple_number_to_words(number - rest)
61
+ second_digit = simple_number_to_words_combined(rest)
62
+ I18n.t(format, :locale => @options[:locale], :first_digit => first_digit, :second_digit => second_digit)
63
+ end
64
+
65
+ # Returns the "combined" number if it exists in the file, otherwise it will return the
66
+ # simple_number_to_words
67
+ def simple_number_to_words_combined(number)
68
+ words = I18n.t("spell_number.numbers.number_#{number}_combined", :locale => @options[:locale], :default => 'not_found')
69
+ words = simple_number_to_words(number) if(words == 'not_found')
70
+ words
71
+ end
72
+
73
+ # Transforms a single-digit number between 0 and 19
74
+ def simple_number_to_words(number)
75
+ I18n.t("spell_number.numbers.number_#{number}", :locale => @options[:locale], :default => 'not_found')
76
+ end
77
+
78
+ def format_subtype(rest)
79
+ case rest
80
+ when 0
81
+ 'no_rest'
82
+ when 1..99
83
+ 'two_digit_rest'
84
+ else
85
+ 'rest'
86
+ end
87
+ end
88
+
89
+ end
90
+
91
+ end
@@ -0,0 +1,12 @@
1
+ require 'spell_number/speller'
2
+ require 'i18n'
3
+
4
+ module SpellNumber
5
+
6
+ I18n.load_path << Dir[File.join(File.dirname(__FILE__), '..', 'locales', '*.{rb,yml}').to_s]
7
+
8
+ def self.number_to_words(number, options = {})
9
+ Speller.new(options).number_to_words(number)
10
+ end
11
+
12
+ end
data/locales/de.yml ADDED
@@ -0,0 +1,51 @@
1
+ de:
2
+ spell_number:
3
+ numbers:
4
+ number_1: eins
5
+ number_1_combined: ein
6
+ number_2: zwei
7
+ number_3: drei
8
+ number_4: vier
9
+ number_5: fünf
10
+ number_6: sechs
11
+ number_7: sieben
12
+ number_8: acht
13
+ number_9: neun
14
+ number_10: zehn
15
+ number_11: elf
16
+ number_12: zwölf
17
+ number_13: dreizehn
18
+ number_14: vierzehn
19
+ number_15: fünfzehn
20
+ number_16: sechzehn
21
+ number_17: siebzehn
22
+ number_18: achtzehn
23
+ number_19: neunzehn
24
+ number_20: zwanzig
25
+ number_30: dreissig
26
+ number_40: vierzig
27
+ number_50: fünfzig
28
+ number_60: sechzig
29
+ number_70: siebzig
30
+ number_80: achtzig
31
+ number_90: neunzig
32
+ number_0: "null"
33
+ formats:
34
+ tens:
35
+ no_rest: "%{first_digit}"
36
+ rest: "%{second_digit}und%{first_digit}"
37
+ hundreds:
38
+ no_rest: "%{hundred_count}hundert"
39
+ rest: "%{hundred_count}hundert%{rest}"
40
+ thousands:
41
+ no_rest: "%{thousand_count}tausend"
42
+ two_digit_rest: "%{thousand_count}tausend%{rest}"
43
+ rest: "%{thousand_count}tausend%{rest}"
44
+ millions_singular:
45
+ no_rest: "eine Million"
46
+ two_digit_rest: "eine Million und %{rest}"
47
+ rest: "eine Million und %{rest}"
48
+ millions:
49
+ no_rest: "%{million_count} Millionen"
50
+ two_digit_rest: "%{million_count} Millionen und %{rest}"
51
+ rest: "%{million_count} Millionen und %{rest}"
data/locales/en.yml ADDED
@@ -0,0 +1,47 @@
1
+ en:
2
+ spell_number:
3
+ numbers:
4
+ number_1: one
5
+ number_2: two
6
+ number_3: three
7
+ number_4: four
8
+ number_5: five
9
+ number_6: six
10
+ number_7: seven
11
+ number_8: eight
12
+ number_9: nine
13
+ number_10: ten
14
+ number_11: eleven
15
+ number_12: twelve
16
+ number_13: thirteen
17
+ number_14: fourteen
18
+ number_15: fifteen
19
+ number_16: sixteen
20
+ number_17: seventeen
21
+ number_18: eighteen
22
+ number_19: nineteen
23
+ number_20: twenty
24
+ number_30: thirty
25
+ number_40: fourty
26
+ number_50: fifty
27
+ number_60: sixty
28
+ number_70: seventy
29
+ number_80: eighty
30
+ number_90: ninety
31
+ number_0: zero
32
+ formats:
33
+ tens:
34
+ no_rest: "%{first_digit}"
35
+ rest: "%{first_digit}-%{second_digit}"
36
+ hundreds:
37
+ no_rest: "%{hundred_count} hundred"
38
+ rest: "%{hundred_count} hundred and %{rest}"
39
+ thousands:
40
+ no_rest: "%{thousand_count} thousand"
41
+ two_digit_rest: "%{thousand_count} thousand and %{rest}"
42
+ rest: "%{thousand_count} thousand, %{rest}"
43
+ millions:
44
+ no_rest: "%{million_count} million"
45
+ two_digit_rest: "%{million_count} million and %{rest}"
46
+ rest: "%{million_count} million, %{rest}"
47
+
@@ -0,0 +1,304 @@
1
+ require 'spell_number'
2
+
3
+ describe "spell numbers in german" do
4
+
5
+ def test_number(number, result)
6
+ SpellNumber.number_to_words(number, :locale => 'de').should == result
7
+ end
8
+
9
+ describe "Single digits" do
10
+ it "should transform 1" do
11
+ test_number(1, 'eins')
12
+ end
13
+
14
+ it "should transform 2" do
15
+ test_number(2, 'zwei')
16
+ end
17
+
18
+ it "should transform 3" do
19
+ test_number(3, 'drei')
20
+ end
21
+
22
+ it "should transform 4" do
23
+ test_number(4, 'vier')
24
+ end
25
+
26
+ it "should transform 5" do
27
+ test_number(5, 'fünf')
28
+ end
29
+
30
+ it "should transform 6" do
31
+ test_number(6, 'sechs')
32
+ end
33
+
34
+ it "should transform 7" do
35
+ test_number(7, 'sieben')
36
+ end
37
+
38
+ it "should transform 8" do
39
+ test_number(8, 'acht')
40
+ end
41
+
42
+ it "should transform 9" do
43
+ test_number(9, 'neun')
44
+ end
45
+
46
+ it "should transform 10" do
47
+ test_number(0, 'null')
48
+ end
49
+ end
50
+
51
+ describe "Teens" do
52
+
53
+ it "should spell 10 as zehn" do
54
+ test_number(10, 'zehn')
55
+ end
56
+
57
+ it "should spell 11 as elf" do
58
+ test_number(11, 'elf')
59
+ end
60
+
61
+ it "should spell 12 as zwölf" do
62
+ test_number(12, 'zwölf')
63
+ end
64
+
65
+ it "should spell 13 as dreizehn" do
66
+ test_number(13, 'dreizehn')
67
+ end
68
+
69
+ it "should spell 14 as vierzehn" do
70
+ test_number(14, 'vierzehn')
71
+ end
72
+
73
+ it "should spell 15 as fünfzehn" do
74
+ test_number(15, 'fünfzehn')
75
+ end
76
+
77
+ it "should spell 16 as sechzehn" do
78
+ test_number(16, 'sechzehn')
79
+ end
80
+
81
+ it "should spell 17 as siebzehn" do
82
+ test_number(17, 'siebzehn')
83
+ end
84
+
85
+ it "should spell 18 as achtzehn" do
86
+ test_number(18, 'achtzehn')
87
+ end
88
+
89
+ it "should spell 19 as neunzehn" do
90
+ test_number(19, 'neunzehn')
91
+ end
92
+ end
93
+
94
+ describe "Twenties" do
95
+
96
+ it "should spell 20 as zwanzig" do
97
+ test_number(20, 'zwanzig')
98
+ end
99
+
100
+ it "should spell 21 as einundzwanzig" do
101
+ test_number(21, 'einundzwanzig')
102
+ end
103
+
104
+ it "should spell 22 as zweiundzwanzig" do
105
+ test_number(22, 'zweiundzwanzig')
106
+ end
107
+
108
+ it "should spell 23 as dreiundzwanzig" do
109
+ test_number(23, 'dreiundzwanzig')
110
+ end
111
+
112
+ it "should spell 24 as vierundzwanzig" do
113
+ test_number(24, 'vierundzwanzig')
114
+ end
115
+
116
+ it "should spell 25 as fünfundzwanzig" do
117
+ test_number(25, 'fünfundzwanzig')
118
+ end
119
+
120
+ it "should spell 26 as sechsundzwanzig" do
121
+ test_number(26, 'sechsundzwanzig')
122
+ end
123
+
124
+ it "should spell 27 as siebenundzwanzig" do
125
+ test_number(27, 'siebenundzwanzig')
126
+ end
127
+
128
+ it "should spell 28 as achtundzwanzig" do
129
+ test_number(28, 'achtundzwanzig')
130
+ end
131
+
132
+ it "should spell 29 as neunundzwanzig" do
133
+ test_number(29, 'neunundzwanzig')
134
+ end
135
+ end
136
+
137
+ describe "Thirties" do
138
+ it "should spell 30 as dreissig" do
139
+ test_number(30, 'dreissig')
140
+ end
141
+
142
+ it "should spell 33 as dreiundreissig" do
143
+ test_number(33, 'dreiunddreissig')
144
+ end
145
+ end
146
+
147
+ describe "Fourties" do
148
+ it "should spell 40 as vierzig" do
149
+ test_number(40, 'vierzig')
150
+ end
151
+
152
+ it "should spell 44 as vierundvierzig" do
153
+ test_number(44, 'vierundvierzig')
154
+ end
155
+ end
156
+
157
+ describe "Fifties" do
158
+ it "should spell 50 as fünfzig" do
159
+ test_number(50, 'fünfzig')
160
+ end
161
+
162
+ it "should spell 55 as fünfundfünfzig" do
163
+ test_number(55, 'fünfundfünfzig')
164
+ end
165
+ end
166
+
167
+ describe "Sixties" do
168
+ it "should spell 60 as sechzig" do
169
+ test_number(60, 'sechzig')
170
+ end
171
+
172
+ it "should spell 66 as sechsundsechzig" do
173
+ test_number(66, 'sechsundsechzig')
174
+ end
175
+ end
176
+
177
+ describe "Seventies" do
178
+ it "should spell 70 as siebzig" do
179
+ test_number(70, 'siebzig')
180
+ end
181
+
182
+ it "should spell 77 as siebenundsiebzig" do
183
+ test_number(77, 'siebenundsiebzig')
184
+ end
185
+ end
186
+
187
+ describe "Eighties" do
188
+ it "should spell 80 as achtzig" do
189
+ test_number(80, 'achtzig')
190
+ end
191
+
192
+ it "should spell 88 as achtundachtzig" do
193
+ test_number(88, 'achtundachtzig')
194
+ end
195
+ end
196
+
197
+ describe "Nineties" do
198
+ it "should spell 90 as neunzig" do
199
+ test_number(90, 'neunzig')
200
+ end
201
+
202
+ it "should spell 99 as neunundneunzig" do
203
+ test_number(99, 'neunundneunzig')
204
+ end
205
+ end
206
+
207
+
208
+ describe "Hundreds" do
209
+ it "should spell 100 as einhundert" do
210
+ test_number(100, 'einhundert')
211
+ end
212
+
213
+ it "should spell 101 as einhundertundeins" do
214
+ test_number(101, 'einhunderteins')
215
+ end
216
+
217
+ it "should spell 111 as einhundertundelf" do
218
+ test_number(111, 'einhundertelf')
219
+ end
220
+
221
+ it "should spell 155 as einhundertundfünfundfünfzig" do
222
+ test_number(155, 'einhundertfünfundfünfzig')
223
+ end
224
+
225
+ it "should spell 190 as einhundertneunzig" do
226
+ test_number(190, 'einhundertneunzig')
227
+ end
228
+
229
+ it "should spell 200 as zweihundert" do
230
+ test_number(200, 'zweihundert')
231
+ end
232
+
233
+ it "should spell 222 as zweihundertzeiundzwanzig" do
234
+ test_number(222, 'zweihundertzweiundzwanzig')
235
+ end
236
+
237
+ it "should spell 999 as neunhundertneunundneunzig" do
238
+ test_number(999, 'neunhundertneunundneunzig')
239
+ end
240
+ end
241
+
242
+ describe "Thousands" do
243
+
244
+ it "should spell 1000 as eintausend" do
245
+ test_number(1000, 'eintausend')
246
+ end
247
+
248
+ it "should spell 1001 as eintausendeins" do
249
+ test_number(1001, 'eintausendeins')
250
+ end
251
+
252
+ it "should spell 1011 as eintausendelf" do
253
+ test_number(1011, 'eintausendelf')
254
+ end
255
+
256
+ it "should spell 1100 as eintausendeinhundert" do
257
+ test_number(1100, 'eintausendeinhundert')
258
+ end
259
+
260
+ it "should spell 1111 as eintausendeinhundertelf" do
261
+ test_number(1111, 'eintausendeinhundertelf')
262
+ end
263
+
264
+ it "should spell 999,999 as neunhundertneunundneunzigtausendneunhundertneunundneunzig" do
265
+ test_number(999999, 'neunhundertneunundneunzigtausendneunhundertneunundneunzig')
266
+ end
267
+
268
+ end
269
+
270
+
271
+ describe "Millions" do
272
+
273
+ it "should spell 1.000.000 as eine Million" do
274
+ test_number(1000000, 'eine Million')
275
+ end
276
+
277
+ it "should spell 1.000.001 as eine Million und eins" do
278
+ test_number(1000001, 'eine Million und eins')
279
+ end
280
+
281
+ it "should spell 1.000.011 as eine Million und elf" do
282
+ test_number(1000011, 'eine Million und elf')
283
+ end
284
+
285
+ it "should spell 1.000.100 as eine Million und einhundert" do
286
+ test_number(1000100, 'eine Million und einhundert')
287
+ end
288
+
289
+ it "should spell 1.000.111 as eine Million und einhundertelf" do
290
+ test_number(1000111, 'eine Million und einhundertelf')
291
+ end
292
+
293
+ it "should spell 1.001.111 as eine Million und eintausendeinhundertelf" do
294
+ test_number(1001111, 'eine Million und eintausendeinhundertelf')
295
+ end
296
+
297
+ it "should spell 999.999.999.999 as neunhundertneunundneunzigtausendneunundneunzig Millionen und neunhundertneunundneunzigtausendneunundneunzig" do
298
+ test_number(999999999999, 'neunhundertneunundneunzigtausendneunhundertneunundneunzig Millionen und neunhundertneunundneunzigtausendneunhundertneunundneunzig')
299
+ end
300
+
301
+ end
302
+
303
+
304
+ end
@@ -0,0 +1,301 @@
1
+ require 'spell_number'
2
+
3
+ describe "spell numbers in english" do
4
+
5
+ def test_number(number, result)
6
+ SpellNumber.number_to_words(number, :locale => 'en').should == result
7
+ end
8
+
9
+ describe "Single digits" do
10
+ it "should transform 1" do
11
+ test_number(1, 'one')
12
+ end
13
+
14
+ it "should transform 2" do
15
+ test_number(2, 'two')
16
+ end
17
+
18
+ it "should transform 3" do
19
+ test_number(3, 'three')
20
+ end
21
+
22
+ it "should transform 4" do
23
+ test_number(4, 'four')
24
+ end
25
+
26
+ it "should transform 5" do
27
+ test_number(5, 'five')
28
+ end
29
+
30
+ it "should transform 6" do
31
+ test_number(6, 'six')
32
+ end
33
+
34
+ it "should transform 7" do
35
+ test_number(7, 'seven')
36
+ end
37
+
38
+ it "should transform 8" do
39
+ test_number(8, 'eight')
40
+ end
41
+
42
+ it "should transform 9" do
43
+ test_number(9, 'nine')
44
+ end
45
+
46
+ it "should transform 10" do
47
+ test_number(0, 'zero')
48
+ end
49
+ end
50
+
51
+ describe "Teens" do
52
+
53
+ it "should spell 10 as ten" do
54
+ test_number(10, 'ten')
55
+ end
56
+
57
+ it "should spell 11 as eleven" do
58
+ test_number(11, 'eleven')
59
+ end
60
+
61
+ it "should spell 12 as twelve" do
62
+ test_number(12, 'twelve')
63
+ end
64
+
65
+ it "should spell 13 as thirteen" do
66
+ test_number(13, 'thirteen')
67
+ end
68
+
69
+ it "should spell 14 as fourteen" do
70
+ test_number(14, 'fourteen')
71
+ end
72
+
73
+ it "should spell 15 as fifteen" do
74
+ test_number(15, 'fifteen')
75
+ end
76
+
77
+ it "should spell 16 as sixteen" do
78
+ test_number(16, 'sixteen')
79
+ end
80
+
81
+ it "should spell 17 as seventeen" do
82
+ test_number(17, 'seventeen')
83
+ end
84
+
85
+ it "should spell 18 as eighteen" do
86
+ test_number(18, 'eighteen')
87
+ end
88
+
89
+ it "should spell 19 as nineteen" do
90
+ test_number(19, 'nineteen')
91
+ end
92
+ end
93
+
94
+ describe "Twenties" do
95
+
96
+ it "should spell 20 as twenty" do
97
+ test_number(20, 'twenty')
98
+ end
99
+
100
+ it "should spell 21 as twenty-one" do
101
+ test_number(21, 'twenty-one')
102
+ end
103
+
104
+ it "should spell 22 as twenty-two" do
105
+ test_number(22, 'twenty-two')
106
+ end
107
+
108
+ it "should spell 23 as twenty-three" do
109
+ test_number(23, 'twenty-three')
110
+ end
111
+
112
+ it "should spell 24 as twenty-four" do
113
+ test_number(24, 'twenty-four')
114
+ end
115
+
116
+ it "should spell 25 as twenty-five" do
117
+ test_number(25, 'twenty-five')
118
+ end
119
+
120
+ it "should spell 26 as twenty-six" do
121
+ test_number(26, 'twenty-six')
122
+ end
123
+
124
+ it "should spell 27 as twenty-seven" do
125
+ test_number(27, 'twenty-seven')
126
+ end
127
+
128
+ it "should spell 28 as twenty-eight" do
129
+ test_number(28, 'twenty-eight')
130
+ end
131
+
132
+ it "should spell 29 as twenty-nine" do
133
+ test_number(29, 'twenty-nine')
134
+ end
135
+ end
136
+
137
+ describe "Thirties" do
138
+ it "should spell 30 as thirty" do
139
+ test_number(30, 'thirty')
140
+ end
141
+
142
+ it "should spell 33 as thirty-three" do
143
+ test_number(33, 'thirty-three')
144
+ end
145
+ end
146
+
147
+ describe "Fourties" do
148
+ it "should spell 40 as fourty" do
149
+ test_number(40, 'fourty')
150
+ end
151
+
152
+ it "should spell 44 as fourty-four" do
153
+ test_number(44, 'fourty-four')
154
+ end
155
+ end
156
+
157
+ describe "Fifties" do
158
+ it "should spell 50 as fifty" do
159
+ test_number(50, 'fifty')
160
+ end
161
+
162
+ it "should spell 55 as fifty-five" do
163
+ test_number(55, 'fifty-five')
164
+ end
165
+ end
166
+
167
+ describe "Sixties" do
168
+ it "should spell 60 as sixty" do
169
+ test_number(60, 'sixty')
170
+ end
171
+
172
+ it "should spell 66 as sixty-six" do
173
+ test_number(66, 'sixty-six')
174
+ end
175
+ end
176
+
177
+ describe "Seventies" do
178
+ it "should spell 70 as seventy" do
179
+ test_number(70, 'seventy')
180
+ end
181
+
182
+ it "should spell 77 as seventy-seven" do
183
+ test_number(77, 'seventy-seven')
184
+ end
185
+ end
186
+
187
+ describe "Eighties" do
188
+ it "should spell 80 as eighty" do
189
+ test_number(80, 'eighty')
190
+ end
191
+
192
+ it "should spell 88 as eighty-eight" do
193
+ test_number(88, 'eighty-eight')
194
+ end
195
+ end
196
+
197
+ describe "Nineties" do
198
+ it "should spell 90 as ninety" do
199
+ test_number(90, 'ninety')
200
+ end
201
+
202
+ it "should spell 99 as ninety-nine" do
203
+ test_number(99, 'ninety-nine')
204
+ end
205
+ end
206
+
207
+ describe "Hundreds" do
208
+ it "should spell 100 as one hundred" do
209
+ test_number(100, 'one hundred')
210
+ end
211
+
212
+ it "should spell 101 as one hundred and one" do
213
+ test_number(101, 'one hundred and one')
214
+ end
215
+
216
+ it "should spell 111 as one hundred and eleven" do
217
+ test_number(111, 'one hundred and eleven')
218
+ end
219
+
220
+ it "should spell 155 as one hundred and fifty-five" do
221
+ test_number(155, 'one hundred and fifty-five')
222
+ end
223
+
224
+ it "should spell 190 as one hundred and ninety" do
225
+ test_number(190, 'one hundred and ninety')
226
+ end
227
+
228
+ it "should spell 200 as two hundred" do
229
+ test_number(200, 'two hundred')
230
+ end
231
+
232
+ it "should spell 222 as two hundred and twenty-two" do
233
+ test_number(222, 'two hundred and twenty-two')
234
+ end
235
+
236
+ it "should spell 999 as nine hundred and ninety-nine" do
237
+ test_number(999, 'nine hundred and ninety-nine')
238
+ end
239
+ end
240
+
241
+ describe "Thousands" do
242
+
243
+ it "should spell 1000 as one thousand" do
244
+ test_number(1000, 'one thousand')
245
+ end
246
+
247
+ it "should spell 1001 as one thousand and one" do
248
+ test_number(1001, 'one thousand and one')
249
+ end
250
+
251
+ it "should spell 1011 as one thousand and eleven" do
252
+ test_number(1011, 'one thousand and eleven')
253
+ end
254
+
255
+ it "should spell 1100 as one thousand, one hundred" do
256
+ test_number(1100, 'one thousand, one hundred')
257
+ end
258
+
259
+ it "should spell 1111 as one thousand, one hundred and one" do
260
+ test_number(1111, 'one thousand, one hundred and eleven')
261
+ end
262
+
263
+ it "should spell 999,999 as nine hundred ninety-nine thousand, nine hundred and ninety-nine" do
264
+ test_number(999999, 'nine hundred and ninety-nine thousand, nine hundred and ninety-nine')
265
+ end
266
+
267
+ end
268
+
269
+ describe "Millions" do
270
+
271
+ it "should spell 1.000.000 as one million" do
272
+ test_number(1000000, 'one million')
273
+ end
274
+
275
+ it "should spell 1.000.001 as one million and one" do
276
+ test_number(1000001, 'one million and one')
277
+ end
278
+
279
+ it "should spell 1.000.011 as one million and eleven" do
280
+ test_number(1000011, 'one million and eleven')
281
+ end
282
+
283
+ it "should spell 1.000.100 as one million, one hundred" do
284
+ test_number(1000100, 'one million, one hundred')
285
+ end
286
+
287
+ it "should spell 1.000.111 as one million, one hundred and eleven" do
288
+ test_number(1000000, 'one million')
289
+ end
290
+
291
+ it "should spell 1.001.111 as one million, one thousand, one hundred and eleven" do
292
+ test_number(1001111, 'one million, one thousand, one hundred and eleven')
293
+ end
294
+
295
+ it "should spell 999.999.999.999 as nine hundred ninety-nine thousand million, nine hundred ninenty-nine thousand, nine hundred and ninety-nine" do
296
+ test_number(999999999999, 'nine hundred and ninety-nine thousand, nine hundred and ninety-nine million, nine hundred and ninety-nine thousand, nine hundred and ninety-nine')
297
+ end
298
+
299
+ end
300
+
301
+ end
@@ -0,0 +1,70 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{spell_number}
8
+ s.version = "0.0.1"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Daniel Hahn"]
12
+ s.date = %q{2011-02-17}
13
+ s.description = %q{Simple Gem to spell numbers as words}
14
+ s.email = %q{developers@betterplace.org}
15
+ s.extra_rdoc_files = [
16
+ "LICENSE.txt",
17
+ "README.rdoc"
18
+ ]
19
+ s.files = [
20
+ ".document",
21
+ "Gemfile",
22
+ "Gemfile.lock",
23
+ "LICENSE.txt",
24
+ "README.rdoc",
25
+ "Rakefile",
26
+ "VERSION",
27
+ "lib/spell_number.rb",
28
+ "lib/spell_number/speller.rb",
29
+ "locales/de.yml",
30
+ "locales/en.yml",
31
+ "spec/number_to_spell_de_spec.rb",
32
+ "spec/number_to_spell_spec.rb",
33
+ "spell_number.gemspec"
34
+ ]
35
+ s.homepage = %q{http://github.com/betterplace/spell_number}
36
+ s.licenses = ["MIT"]
37
+ s.require_paths = ["lib"]
38
+ s.rubygems_version = %q{1.3.7}
39
+ s.summary = %q{Spell numbers as words}
40
+ s.test_files = [
41
+ "spec/number_to_spell_de_spec.rb",
42
+ "spec/number_to_spell_spec.rb"
43
+ ]
44
+
45
+ if s.respond_to? :specification_version then
46
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
47
+ s.specification_version = 3
48
+
49
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
50
+ s.add_runtime_dependency(%q<i18n>, [">= 0.3.7"])
51
+ s.add_development_dependency(%q<rspec>, ["~> 2.3.0"])
52
+ s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
53
+ s.add_development_dependency(%q<jeweler>, ["~> 1.5.2"])
54
+ s.add_development_dependency(%q<rcov>, [">= 0"])
55
+ else
56
+ s.add_dependency(%q<i18n>, [">= 0.3.7"])
57
+ s.add_dependency(%q<rspec>, ["~> 2.3.0"])
58
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
59
+ s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
60
+ s.add_dependency(%q<rcov>, [">= 0"])
61
+ end
62
+ else
63
+ s.add_dependency(%q<i18n>, [">= 0.3.7"])
64
+ s.add_dependency(%q<rspec>, ["~> 2.3.0"])
65
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
66
+ s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
67
+ s.add_dependency(%q<rcov>, [">= 0"])
68
+ end
69
+ end
70
+
metadata ADDED
@@ -0,0 +1,159 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: spell_number
3
+ version: !ruby/object:Gem::Version
4
+ hash: 29
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 1
10
+ version: 0.0.1
11
+ platform: ruby
12
+ authors:
13
+ - Daniel Hahn
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2011-02-17 00:00:00 +01:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ type: :runtime
23
+ prerelease: false
24
+ name: i18n
25
+ version_requirements: &id001 !ruby/object:Gem::Requirement
26
+ none: false
27
+ requirements:
28
+ - - ">="
29
+ - !ruby/object:Gem::Version
30
+ hash: 29
31
+ segments:
32
+ - 0
33
+ - 3
34
+ - 7
35
+ version: 0.3.7
36
+ requirement: *id001
37
+ - !ruby/object:Gem::Dependency
38
+ type: :development
39
+ prerelease: false
40
+ name: rspec
41
+ version_requirements: &id002 !ruby/object:Gem::Requirement
42
+ none: false
43
+ requirements:
44
+ - - ~>
45
+ - !ruby/object:Gem::Version
46
+ hash: 3
47
+ segments:
48
+ - 2
49
+ - 3
50
+ - 0
51
+ version: 2.3.0
52
+ requirement: *id002
53
+ - !ruby/object:Gem::Dependency
54
+ type: :development
55
+ prerelease: false
56
+ name: bundler
57
+ version_requirements: &id003 !ruby/object:Gem::Requirement
58
+ none: false
59
+ requirements:
60
+ - - ~>
61
+ - !ruby/object:Gem::Version
62
+ hash: 23
63
+ segments:
64
+ - 1
65
+ - 0
66
+ - 0
67
+ version: 1.0.0
68
+ requirement: *id003
69
+ - !ruby/object:Gem::Dependency
70
+ type: :development
71
+ prerelease: false
72
+ name: jeweler
73
+ version_requirements: &id004 !ruby/object:Gem::Requirement
74
+ none: false
75
+ requirements:
76
+ - - ~>
77
+ - !ruby/object:Gem::Version
78
+ hash: 7
79
+ segments:
80
+ - 1
81
+ - 5
82
+ - 2
83
+ version: 1.5.2
84
+ requirement: *id004
85
+ - !ruby/object:Gem::Dependency
86
+ type: :development
87
+ prerelease: false
88
+ name: rcov
89
+ version_requirements: &id005 !ruby/object:Gem::Requirement
90
+ none: false
91
+ requirements:
92
+ - - ">="
93
+ - !ruby/object:Gem::Version
94
+ hash: 3
95
+ segments:
96
+ - 0
97
+ version: "0"
98
+ requirement: *id005
99
+ description: Simple Gem to spell numbers as words
100
+ email: developers@betterplace.org
101
+ executables: []
102
+
103
+ extensions: []
104
+
105
+ extra_rdoc_files:
106
+ - LICENSE.txt
107
+ - README.rdoc
108
+ files:
109
+ - .document
110
+ - Gemfile
111
+ - Gemfile.lock
112
+ - LICENSE.txt
113
+ - README.rdoc
114
+ - Rakefile
115
+ - VERSION
116
+ - lib/spell_number.rb
117
+ - lib/spell_number/speller.rb
118
+ - locales/de.yml
119
+ - locales/en.yml
120
+ - spec/number_to_spell_de_spec.rb
121
+ - spec/number_to_spell_spec.rb
122
+ - spell_number.gemspec
123
+ has_rdoc: true
124
+ homepage: http://github.com/betterplace/spell_number
125
+ licenses:
126
+ - MIT
127
+ post_install_message:
128
+ rdoc_options: []
129
+
130
+ require_paths:
131
+ - lib
132
+ required_ruby_version: !ruby/object:Gem::Requirement
133
+ none: false
134
+ requirements:
135
+ - - ">="
136
+ - !ruby/object:Gem::Version
137
+ hash: 3
138
+ segments:
139
+ - 0
140
+ version: "0"
141
+ required_rubygems_version: !ruby/object:Gem::Requirement
142
+ none: false
143
+ requirements:
144
+ - - ">="
145
+ - !ruby/object:Gem::Version
146
+ hash: 3
147
+ segments:
148
+ - 0
149
+ version: "0"
150
+ requirements: []
151
+
152
+ rubyforge_project:
153
+ rubygems_version: 1.3.7
154
+ signing_key:
155
+ specification_version: 3
156
+ summary: Spell numbers as words
157
+ test_files:
158
+ - spec/number_to_spell_de_spec.rb
159
+ - spec/number_to_spell_spec.rb