public
Description: Converts numbers, currency and other units to Polish, English, German
Homepage: http://trix.pl
Clone URL: git://github.com/tomaszmazur/verbal.git
Click here to lend your support to: verbal and make a donation at www.pledgie.com !
tests for conversion to english words, one bug hunted :)
tomaszmazur (author)
Fri Aug 01 03:20:21 -0700 2008
commit  246509baaab89202420fee4b000b14fe8358dd4b
tree    c49cfb34c8da307b095af74ffdb2b8d6b2b61a20
parent  9a7d680de6503cfc3ee6f5e1d5d34d25d7e7ac0b
...
1
 
2
3
4
5
6
7
 
8
...
 
1
2
 
 
 
 
3
4
5
0
@@ -1,6 +1,3 @@
0
-== CHANGELOG:
0
+=== 1.0.0 / 2008-08-01
0
 
0
-25/07/2008: currency_in_words now recognizes grammatical gender of currency
0
- '2 PLN' => dwa złote, but '2 SKK' => dwie korony słowackie (not 'dwa korony słowackie')
0
-25/07/2008: Changed squish method to strip (as squish is specific for Rails)
0
- Added TODO tasks
0
\ No newline at end of file
0
+Verbal is now a gem!
0
\ No newline at end of file
...
1
2
3
4
 
 
5
6
7
8
 
 
 
 
 
 
 
9
...
1
2
3
 
4
5
6
7
 
8
9
10
11
12
13
14
15
16
0
@@ -1,7 +1,14 @@
0
 History.txt
0
 Manifest.txt
0
 README.txt
0
-verbal.gemspec
0
+Rakefile
0
+bin/verbal
0
 lib/verbal.rb
0
 lib/verbal/core.rb
0
-lib/currency/currency.rb
0
\ No newline at end of file
0
+lib/verbal/english/numbers.rb
0
+lib/verbal/polish/currency.rb
0
+lib/verbal/polish/numbers.rb
0
+spec/spec_helper.rb
0
+spec/unit/currency.rb
0
+spec/unit/numbers.rb
0
+verbal.gemspec
0
\ No newline at end of file
...
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
 
4
5
 
6
7
 
8
9
10
 
11
12
13
 
14
15
16
 
17
18
 
 
 
 
 
 
 
19
20
21
 
 
22
23
24
 
 
 
 
 
 
 
...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
 
43
44
 
45
46
 
47
48
 
 
49
50
 
 
51
52
 
 
53
54
 
55
56
57
58
59
60
61
62
 
 
63
64
65
 
66
67
68
69
70
71
72
73
0
@@ -1,23 +1,72 @@
0
+= verbal
0
+
0
+ http://trix.lighthouseapp.com/projects/14763-verbal
0
+
0
+== DESCRIPTION:
0
+
0
+ Converts numbers to words (its text presentation)
0
+ Currently supported languages are:
0
+
0
+ - English *
0
+ - Polish
0
+
0
+ NOTE: It's American English numbering system
0
+ http://www.mazes.com/AmericanNumberingSystem.html
0
+
0
+== FEATURES/PROBLEMS:
0
+
0
+
0
+
0
+== SYNOPSIS:
0
+
0
+1) NUMBERS:
0
+
0
+ Verbal::Polish::Numbers.to_words(123_456_789)
0
+ => "sto dwadzieścia trzy miliony czterysta pięćdziesiąt sześć tysiecy siedemset osiemdziesiąt dziewięć"
0
+
0
+ Verbal::English::Numbers.to_words(123_456_789)
0
+ => "one hundred twenty-three million four hundred fifty-six thousand seven hundred and eighty-nine"
0
+
0
+ 2) CURRENCIES:
0
+
0
+ Verbal::Polish::Currency.to_words(123_456_789_00, 'PLN')
0
+ => "sto dwadzieścia trzy miliony czterysta pięćdziesiąt sześć tysiecy siedemset osiemdziesiąt dziewięć złotych zero groszy"
0
+
0
+ No Support for Verbal::English::Currency yet... Anybody?
0
+
0
+== REQUIREMENTS:
0
+
0
+
0
+
0
 == INSTALL:
0
 
0
-script/plugin install git://github.com/tomaszmazur/verbal.git
0
+ sudo gem install verbal
0
 
0
-== USAGE:
0
+ or
0
 
0
-NUMBERS:
0
+ script/plugin install git://github.com/tomaszmazur/verbal.git
0
 
0
-Verbal::Polish::Numbers.to_words(123_456_789)
0
-=> "sto dwadzieścia trzy miliony czterysta pięćdziesiąt sześć tysiecy siedemset osiemdziesiąt dziewięć"
0
+== LICENSE:
0
 
0
-NOTE: It's American English numbering system
0
-http://www.mazes.com/AmericanNumberingSystem.html
0
+(The MIT License)
0
 
0
-Verbal::English::Numbers.to_words(123_456_789)
0
-=> "one hundred twenty-three million four hundred fifty-six thousand seven hundred and eighty-nine"
0
+Copyright (c) 2008 Tomasz Mazur
0
 
0
-CURRENCIES:
0
+Permission is hereby granted, free of charge, to any person obtaining
0
+a copy of this software and associated documentation files (the
0
+'Software'), to deal in the Software without restriction, including
0
+without limitation the rights to use, copy, modify, merge, publish,
0
+distribute, sublicense, and/or sell copies of the Software, and to
0
+permit persons to whom the Software is furnished to do so, subject to
0
+the following conditions:
0
 
0
-Verbal::Polish::Currency.to_words(123_456_789_00, 'PLN')
0
-=> "sto dwadzieścia trzy miliony czterysta pięćdziesiąt sześć tysiecy siedemset osiemdziesiąt dziewięć złotych zero groszy"
0
+The above copyright notice and this permission notice shall be
0
+included in all copies or substantial portions of the Software.
0
 
0
-No Support for Verbal::English::Currency yet... Anybody?
0
\ No newline at end of file
0
+THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
0
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
0
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
0
+IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
0
+CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
0
+TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
0
+SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
...
1
2
3
4
5
6
 
7
...
1
 
2
3
 
 
4
5
0
@@ -1,6 +1,4 @@
0
 require File.dirname(__FILE__) + '/verbal/core'
0
-# polish
0
 require File.dirname(__FILE__) + '/verbal/polish/numbers'
0
 require File.dirname(__FILE__) + '/verbal/polish/currency'
0
-# english
0
-require File.dirname(__FILE__) + '/verbal/english/numbers'
0
+require File.dirname(__FILE__) + '/verbal/english/numbers'
0
\ No newline at end of file
...
1
 
 
 
2
3
4
...
1
2
3
4
5
6
7
0
@@ -1,4 +1,7 @@
0
 module Verbal
0
+
0
+ VERSION = '1.0.0'
0
+
0
   module Core
0
 
0
     def exponent(value)
...
1
2
3
 
4
5
6
...
45
46
47
48
 
49
 
 
50
51
52
 
 
53
54
55
56
57
58
59
60
61
 
 
 
 
 
 
 
 
 
 
 
 
62
63
 
 
64
65
66
67
68
69
70
71
 
 
 
 
72
73
 
74
75
 
76
77
78
...
1
2
 
3
4
5
6
...
45
46
47
 
48
49
50
51
52
 
 
53
54
55
56
57
58
 
 
 
 
 
59
60
61
62
63
64
65
66
67
68
69
70
71
 
72
73
74
75
76
 
 
 
 
 
77
78
79
80
81
 
82
83
 
84
85
86
87
0
@@ -1,6 +1,6 @@
0
 module Verbal
0
   module English
0
- # American English
0
+
0
     module Numbers
0
 
0
       EXPONENT_EN = {
0
@@ -45,34 +45,43 @@ module Verbal
0
         19 => 'nineteen'
0
       }
0
 
0
- def to_words(value, gender = 0)
0
+ def to_words(value)
0
         raise 'value must be an integer' unless value.is_a?(Integer)
0
+ @exponent = Verbal::Core::exponent(value)
0
+ @extracted_exponents = Verbal::Core::process_thousands(value)
0
         @in_words = ''
0
- Verbal::Core.process_thousands(value).each do |e, v|
0
- @in_words << "#{v < 100 ? process_tens(v, e) : process_hundreds(v, e)} #{EXPONENT_EN[e]} "
0
+ @extracted_exponents.each do |e, v|
0
+ @in_words << "#{process_hundreds(v, e, @exponent)} #{EXPONENT_EN[e]} "
0
         end
0
         return @in_words.strip.squeeze(' ')
0
       end
0
 
0
- def process_hundreds(value, exponent)
0
- raise IncorrectInputValue unless (100..999).include?(value)
0
- hundreds_count = value / 100
0
- if (value % 100) == 0
0
- return NUMBERS_EN[hundreds_count] + ' hundred'
0
+ def process_hundreds(value, current_exponent, value_exponent)
0
+ raise 'value should be in range: 0.999' unless (0..999).include?(value)
0
+ if value > 100
0
+
0
+ hundreds_count = value / 100
0
+ if value % 100 == 0
0
+ return NUMBERS_EN[hundreds_count] + ' hundred'
0
+ else
0
+ prefix = "#{(value_exponent != 0 && current_exponent == 0) ? ' and ': ''}"
0
+ return NUMBERS_EN[hundreds_count] + ' hundred ' + process_tens(value % 100, prefix)
0
+ end
0
+
0
         else
0
- return NUMBERS_EN[hundreds_count] + ' hundred ' + process_tens(value % 100, exponent)
0
+ prefix = "#{(value_exponent != 0 && current_exponent == 0) ? ' and ': ''}"
0
+ return process_tens(value % 100, prefix)
0
         end
0
       end
0
 
0
- def process_tens(value, exponent)
0
- raise IncorrectInputValue unless (0..99).include?(value)
0
- and_string = exponent > 0 ? '' : 'and '
0
- return and_string + NUMBERS_EN[value] if value < 9
0
- return and_string + NUMBERS_EN[(value / 10) * 10] if (value % 10) == 0
0
+ def process_tens(value, prefix)
0
+ raise 'value should be in range: 0..99' unless (0..99).include?(value)
0
+ return prefix + NUMBERS_EN[value] if value < 9
0
+ return prefix + NUMBERS_EN[(value / 10) * 10] if (value % 10) == 0
0
         if (11..19).include?(value)
0
- return and_string + NUMBERS_EN[value]
0
+ return prefix + NUMBERS_EN[value]
0
         else
0
- return and_string + NUMBERS_EN[(value / 10) * 10] + '-' + NUMBERS_EN[value % 10]
0
+ return prefix + NUMBERS_EN[(value / 10) * 10] + '-' + NUMBERS_EN[value % 10]
0
         end
0
       end
0
 
...
1
2
3
 
4
5
6
...
1
2
 
3
4
5
6
0
@@ -1,6 +1,6 @@
0
 require File.join(File.dirname(__FILE__), '..', 'spec_helper')
0
 
0
-describe Verbal::Currency do
0
+describe Verbal::Polish::Currency do
0
 
0
   it 'should return correct string' do
0
     Verbal::Polish::Currency.to_words(0).should == 'zero złotych zero groszy'
...
1
2
3
 
4
5
6
...
29
30
31
 
 
 
 
 
 
 
 
 
 
 
...
1
2
 
3
4
5
6
...
29
30
31
32
33
34
35
36
37
38
39
40
41
42
0
@@ -1,6 +1,6 @@
0
 require File.join(File.dirname(__FILE__), '..', 'spec_helper')
0
 
0
-describe Verbal::Numbers do
0
+describe Verbal::Polish::Numbers do
0
 
0
   it 'should return correct string' do
0
     Verbal::Polish::Numbers.to_words(0).should == 'zero'
0
@@ -29,3 +29,14 @@ describe Verbal::Numbers do
0
   end
0
 
0
 end
0
+
0
+
0
+describe Verbal::English::Numbers do
0
+
0
+ it 'should return correct string' do
0
+ Verbal::English::Numbers.to_words(34).should == "thirty-four"
0
+ Verbal::English::Numbers.to_words(2_001).should == "two thousand and one"
0
+ Verbal::English::Numbers.to_words(1_134).should == "one thousand one hundred and thirty-four"
0
+ end
0
+
0
+end
...
1
2
3
4
5
6
7
8
9
10
11
12
 
 
 
 
 
 
 
 
13
 
 
 
 
 
 
 
 
 
14
15
...
1
 
 
 
 
 
 
 
 
 
 
 
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
0
@@ -1,14 +1,20 @@
0
 Gem::Specification.new do |s|
0
- s.name = "verbal"
0
- s.version = "0.2"
0
- s.date = "2008-07-25"
0
- s.summary = "Converts numbers, currency and other units to Polish (more to come)"
0
- s.email = "tomek@trix.pl"
0
- s.homepage = "http://github.com/tomaszmazur/verbal"
0
- s.description = "Verbal - library for converting units (time, currency, weight, height) to Polish words. More languages to come"
0
- s.has_rdoc = false
0
- s.authors = ["Tomasz Mazur"]
0
- s.files = ["History.txt", "Manifest.txt", "README.txt", "verbal.gemspec", "lib/currency/currency.rb", "lib/verbal/core.rb", "lib/verbal.rb"]
0
- s.rdoc_options = ["--main", "README.txt"]
0
+ s.name = %q{verbal}
0
+ s.version = "1.0.0"
0
+
0
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
0
+ s.authors = ["Tomasz Mazur"]
0
+ s.date = %q{2008-08-01}
0
+ s.description = %q{Converts numbers to words (its text presentation) Currently supported languages are: -English * - Polish NOTE: It's American English numbering system http://www.mazes.com/AmericanNumberingSystem.html}
0
+ s.email = ["tomek@trix.pl"]
0
   s.extra_rdoc_files = ["History.txt", "Manifest.txt", "README.txt"]
0
+ s.files = ["History.txt", "Manifest.txt", "README.txt", "Rakefile", "lib/verbal.rb", "lib/verbal/core.rb","lib/verbal/english/numbers.rb", "lib/verbal/polish/numbers.rb", "lib/verbal/polish/currency.rb", "spec/spec_helper.rb", "spec/unit/currency.rb", "spec/unit/numbers.rb"]
0
+ s.has_rdoc = true
0
+ s.homepage = %q{ http://trix.lighthouseapp.com/projects/14763-verbal}
0
+ s.rdoc_options = ["--main", "README.txt"]
0
+ s.require_paths = ["lib"]
0
+ s.rubyforge_project = %q{verbal}
0
+ s.rubygems_version = %q{1.2.0}
0
+ s.summary = %q{Converts numbers to words (its text presentation) Currently supported languages are: - English * - Polish NOTE: It's American English numbering system http://www.mazes.com/AmericanNumberingSystem.html}
0
+
0
 end
0
\ No newline at end of file

Comments

    No one has commented yet.