numbers_and_words 0.5.0 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +15 -0
- data/README.rdoc +90 -1
- data/lib/numbers_and_words.rb +4 -3
- data/lib/numbers_and_words/core_ext.rb +1 -0
- data/lib/numbers_and_words/core_ext/array.rb +1 -1
- data/lib/numbers_and_words/core_ext/float.rb +5 -0
- data/lib/numbers_and_words/core_ext/integer.rb +2 -9
- data/lib/numbers_and_words/helper_classes.rb +2 -0
- data/lib/numbers_and_words/helper_classes/array_extensions/helpers.rb +81 -0
- data/lib/numbers_and_words/helper_classes/array_extensions/validations.rb +19 -0
- data/lib/numbers_and_words/helper_classes/figures_array.rb +18 -0
- data/lib/numbers_and_words/helper_classes/words_array.rb +11 -0
- data/lib/numbers_and_words/i18n/locales/numbers.en.yml +48 -0
- data/lib/numbers_and_words/i18n/locales/numbers.es.yml +15 -0
- data/lib/numbers_and_words/i18n/locales/numbers.hu.yml +16 -0
- data/lib/numbers_and_words/i18n/locales/numbers.ru.yml +27 -3
- data/lib/numbers_and_words/i18n/locales/numbers.se.yml +7 -0
- data/lib/numbers_and_words/i18n/locales/numbers.ua.yml +14 -2
- data/lib/numbers_and_words/i18n/pluralization.rb +1 -0
- data/lib/numbers_and_words/i18n/plurals/es.rb +11 -0
- data/lib/numbers_and_words/strategies.rb +16 -11
- data/lib/numbers_and_words/strategies/array_joiner.rb +31 -0
- data/lib/numbers_and_words/strategies/figures_converter.rb +33 -0
- data/lib/numbers_and_words/strategies/figures_converter/decorators.rb +39 -0
- data/lib/numbers_and_words/strategies/figures_converter/decorators/base.rb +18 -0
- data/lib/numbers_and_words/strategies/figures_converter/decorators/en.rb +3 -0
- data/lib/numbers_and_words/strategies/figures_converter/decorators/en/base.rb +12 -0
- data/lib/numbers_and_words/strategies/figures_converter/decorators/en/fractional.rb +38 -0
- data/lib/numbers_and_words/strategies/figures_converter/decorators/en/integral.rb +12 -0
- data/lib/numbers_and_words/strategies/figures_converter/decorators/hu.rb +3 -0
- data/lib/numbers_and_words/strategies/figures_converter/decorators/hu/base.rb +12 -0
- data/lib/numbers_and_words/strategies/figures_converter/decorators/hu/fractional.rb +38 -0
- data/lib/numbers_and_words/strategies/figures_converter/decorators/hu/integral.rb +12 -0
- data/lib/numbers_and_words/strategies/figures_converter/decorators/ru.rb +3 -0
- data/lib/numbers_and_words/strategies/figures_converter/decorators/ru/base.rb +12 -0
- data/lib/numbers_and_words/strategies/figures_converter/decorators/ru/fractional.rb +39 -0
- data/lib/numbers_and_words/strategies/figures_converter/decorators/ru/integral.rb +27 -0
- data/lib/numbers_and_words/strategies/figures_converter/decorators/ua.rb +3 -0
- data/lib/numbers_and_words/strategies/figures_converter/decorators/ua/base.rb +12 -0
- data/lib/numbers_and_words/strategies/figures_converter/decorators/ua/fractional.rb +39 -0
- data/lib/numbers_and_words/strategies/figures_converter/decorators/ua/integral.rb +27 -0
- data/lib/numbers_and_words/strategies/figures_converter/languages.rb +39 -0
- data/lib/numbers_and_words/strategies/figures_converter/languages/base.rb +29 -0
- data/lib/numbers_and_words/strategies/figures_converter/languages/en.rb +48 -0
- data/lib/numbers_and_words/strategies/figures_converter/languages/es.rb +37 -0
- data/lib/numbers_and_words/strategies/figures_converter/languages/families/base.rb +77 -0
- data/lib/numbers_and_words/strategies/figures_converter/languages/families/cyrillic.rb +34 -0
- data/lib/numbers_and_words/strategies/figures_converter/languages/families/helpers.rb +36 -0
- data/lib/numbers_and_words/strategies/figures_converter/languages/families/latin.rb +13 -0
- data/lib/numbers_and_words/strategies/figures_converter/languages/fr.rb +37 -0
- data/lib/numbers_and_words/strategies/figures_converter/languages/hu.rb +63 -0
- data/lib/numbers_and_words/strategies/figures_converter/languages/it.rb +11 -0
- data/lib/numbers_and_words/strategies/figures_converter/languages/nl.rb +26 -0
- data/lib/numbers_and_words/strategies/figures_converter/languages/ru.rb +11 -0
- data/lib/numbers_and_words/strategies/figures_converter/languages/se.rb +11 -0
- data/lib/numbers_and_words/strategies/figures_converter/languages/tr.rb +11 -0
- data/lib/numbers_and_words/strategies/figures_converter/languages/ua.rb +11 -0
- data/lib/numbers_and_words/strategies/figures_converter/options.rb +41 -0
- data/lib/numbers_and_words/strategies/figures_converter/options/en.rb +4 -0
- data/lib/numbers_and_words/strategies/figures_converter/options/en/hundreds_with_union.rb +33 -0
- data/lib/numbers_and_words/strategies/figures_converter/options/en/ordinal.rb +60 -0
- data/lib/numbers_and_words/strategies/figures_converter/options/en/remove_hyphen.rb +29 -0
- data/lib/numbers_and_words/strategies/figures_converter/options/en/remove_zero.rb +29 -0
- data/lib/numbers_and_words/strategies/figures_converter/options/hu.rb +1 -0
- data/lib/numbers_and_words/strategies/figures_converter/options/hu/ordinal.rb +60 -0
- data/lib/numbers_and_words/strategies/figures_converter/options/ru.rb +1 -0
- data/lib/numbers_and_words/strategies/figures_converter/options/ru/gender.rb +28 -0
- data/lib/numbers_and_words/strategies/figures_converter/options/ua.rb +1 -0
- data/lib/numbers_and_words/strategies/figures_converter/options/ua/gender.rb +28 -0
- data/lib/numbers_and_words/translations.rb +25 -0
- data/lib/numbers_and_words/{translations_helpers → translations}/base.rb +2 -2
- data/lib/numbers_and_words/translations/en.rb +8 -0
- data/lib/numbers_and_words/translations/es.rb +37 -0
- data/lib/numbers_and_words/translations/extensions/fraction_significance.rb +25 -0
- data/lib/numbers_and_words/translations/families/base.rb +33 -0
- data/lib/numbers_and_words/translations/families/cyrillic.rb +29 -0
- data/lib/numbers_and_words/translations/families/latin.rb +23 -0
- data/lib/numbers_and_words/translations/fr.rb +29 -0
- data/lib/numbers_and_words/translations/hu.rb +26 -0
- data/lib/numbers_and_words/translations/it.rb +15 -0
- data/lib/numbers_and_words/translations/nl.rb +15 -0
- data/lib/numbers_and_words/translations/ru.rb +25 -0
- data/lib/numbers_and_words/translations/se.rb +11 -0
- data/lib/numbers_and_words/translations/tr.rb +11 -0
- data/lib/numbers_and_words/translations/ua.rb +21 -0
- data/lib/numbers_and_words/version.rb +1 -1
- data/lib/numbers_and_words/wrappers.rb +2 -0
- data/lib/numbers_and_words/wrappers/float.rb +60 -0
- data/lib/numbers_and_words/wrappers/integer.rb +21 -0
- metadata +81 -44
- data/lib/numbers_and_words/array_additions.rb +0 -2
- data/lib/numbers_and_words/array_additions/helpers.rb +0 -44
- data/lib/numbers_and_words/array_additions/validations.rb +0 -9
- data/lib/numbers_and_words/figures_array.rb +0 -15
- data/lib/numbers_and_words/strategies/base.rb +0 -18
- data/lib/numbers_and_words/strategies/en.rb +0 -8
- data/lib/numbers_and_words/strategies/families/base.rb +0 -71
- data/lib/numbers_and_words/strategies/families/cyrillic.rb +0 -18
- data/lib/numbers_and_words/strategies/families/latin.rb +0 -9
- data/lib/numbers_and_words/strategies/fr.rb +0 -32
- data/lib/numbers_and_words/strategies/it.rb +0 -8
- data/lib/numbers_and_words/strategies/nl.rb +0 -23
- data/lib/numbers_and_words/strategies/ru.rb +0 -8
- data/lib/numbers_and_words/strategies/tr.rb +0 -8
- data/lib/numbers_and_words/strategies/ua.rb +0 -8
- data/lib/numbers_and_words/translations_helpers.rb +0 -11
- data/lib/numbers_and_words/translations_helpers/en.rb +0 -12
- data/lib/numbers_and_words/translations_helpers/families/base.rb +0 -30
- data/lib/numbers_and_words/translations_helpers/families/cyrillic.rb +0 -28
- data/lib/numbers_and_words/translations_helpers/families/latin.rb +0 -23
- data/lib/numbers_and_words/translations_helpers/fr.rb +0 -34
- data/lib/numbers_and_words/translations_helpers/it.rb +0 -16
- data/lib/numbers_and_words/translations_helpers/nl.rb +0 -18
- data/lib/numbers_and_words/translations_helpers/ru.rb +0 -8
- data/lib/numbers_and_words/translations_helpers/tr.rb +0 -8
- data/lib/numbers_and_words/translations_helpers/ua.rb +0 -8
checksums.yaml
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
---
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
MGQyNDhhNTY5MjhjZTcyYjZjMjg0Y2RhNGVmYWJiNzAwZTU4NWZjNw==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
NzNkZTQ1YTUzMDRkMDI2MTY4MjMzZmU1ZDI0ZWZkNGU4MjBlMzFiYQ==
|
7
|
+
!binary "U0hBNTEy":
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
MDhjMTY3MTg4Mjc1NTBhNDczOTVlYjJhNWMxOWIyOTBjNDI4MjBhYmQxNWRl
|
10
|
+
MGQ1YWMyNzJkMzBkMjAwYTdhMzcyZTAzMjExZGI5Yzg2ZmFiN2ExZTQ1Yjkw
|
11
|
+
NjJmMzk5YmJkMzljOWRiMjMxYjEzZTdmZDgxNDJiYzQ4MzcyZjM=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
NDdmN2Y5ODgyYzA4YjI0OWVlM2ZmNjgxMWEyODE5NGJmNDkyOWExZjJjZGZk
|
14
|
+
YWQzMWIzN2MzOTUwNmJkYzkxNjhhZjBiODNmNGVmNDk4ZWFjYjM1YzZhOTI3
|
15
|
+
ZGViYzkyNWMxOTU3MzY2ZDM2ZjlkY2Q0ODNhOWFhOWFjZWI0MzE=
|
data/README.rdoc
CHANGED
@@ -1,4 +1,10 @@
|
|
1
|
-
== numbers_and_words
|
1
|
+
== numbers_and_words
|
2
|
+
|
3
|
+
{<img src="https://badge.fury.io/rb/numbers_and_words.png" alt="Gem Version" />}[http://badge.fury.io/rb/numbers_and_words]
|
4
|
+
{<img src="https://gemnasium.com/kslazarev/numbers_and_words.png" alt="Dependency Status" />}[https://gemnasium.com/kslazarev/numbers_and_words]
|
5
|
+
{<img src="https://codeclimate.com/github/kslazarev/numbers_and_words.png" />}[https://codeclimate.com/github/kslazarev/numbers_and_words]
|
6
|
+
{<img src="https://secure.travis-ci.org/kslazarev/numbers_and_words.png" />}[http://travis-ci.org/kslazarev/numbers_and_words]
|
7
|
+
{<img src="https://coveralls.io/repos/kslazarev/numbers_and_words/badge.png?branch=development" alt="Coverage Status" />}[https://coveralls.io/r/kslazarev/numbers_and_words]
|
2
8
|
|
3
9
|
Convert numbers to words using the I18n library.
|
4
10
|
|
@@ -6,15 +12,20 @@ Convert numbers to words using the I18n library.
|
|
6
12
|
|
7
13
|
Converti les nombres en lettres en utilisant la librairie I18n.
|
8
14
|
|
15
|
+
Számok betűvel írva az I18n könyvtár segítségével.
|
16
|
+
|
9
17
|
== Supported Languages / Языки / Langues Supportées
|
10
18
|
|
11
19
|
* English
|
20
|
+
* Spanish
|
12
21
|
* Русский
|
13
22
|
* Français
|
14
23
|
* Українська
|
24
|
+
* Magyar
|
15
25
|
* Türkçe**
|
16
26
|
* Italiano**
|
17
27
|
* Nederlands**
|
28
|
+
* Swedish**
|
18
29
|
|
19
30
|
** Experimental
|
20
31
|
|
@@ -23,70 +34,147 @@ Converti les nombres en lettres en utilisant la librairie I18n.
|
|
23
34
|
I18n.with_locale(:en) { 42.to_words }
|
24
35
|
=> "forty-two"
|
25
36
|
|
37
|
+
I18n.with_locale(:es) { 42.to_words }
|
38
|
+
=> "cuarenta y dos"
|
39
|
+
|
26
40
|
I18n.with_locale(:ru) { 42.to_words }
|
27
41
|
=> "сорок два"
|
28
42
|
|
29
43
|
I18n.with_locale(:fr) { 42.to_words }
|
30
44
|
=> "quarante-deux"
|
31
45
|
|
46
|
+
I18n.with_locale(:hu) { 42.to_words }
|
47
|
+
=> "negyvenkettő"
|
48
|
+
|
32
49
|
21.to_words
|
33
50
|
=> "twenty-one"
|
51
|
+
=> "veintiuno"
|
34
52
|
=> "двадцать один"
|
35
53
|
=> "vingt et un"
|
36
54
|
=> "двадцять один"
|
55
|
+
=> "huszonegy"
|
37
56
|
=> "yirmi bir"
|
38
57
|
=> "ventiuno"
|
39
58
|
=> "éénentwintig"
|
59
|
+
=> "tjugo-en"
|
40
60
|
|
41
61
|
231.to_words
|
42
62
|
=> "two hundred thirty-one"
|
63
|
+
=> "doscientos treinta y uno"
|
43
64
|
=> "двести тридцать один"
|
44
65
|
=> "deux cent trente-trois"
|
45
66
|
=> "двiстi тридцять один"
|
67
|
+
=> "kettőszázharmincegy"
|
46
68
|
=> "iki yüz otuz bir"
|
47
69
|
=> "2 cento trentauno"
|
48
70
|
=> "tweehonderdéénendertig"
|
71
|
+
=> "två hundra trettio-en"
|
49
72
|
|
50
73
|
4030.to_words
|
51
74
|
=> "four thousand thirty"
|
75
|
+
=> "cuatro mil treinta"
|
52
76
|
=> "четыре тысячи тридцать"
|
53
77
|
=> "quatre mille trente"
|
54
78
|
=> "чотири тисячi тридцять"
|
79
|
+
=> "négyezer-harminc"
|
55
80
|
=> "dört bin otuz"
|
56
81
|
=> "quattro mille trenta"
|
57
82
|
=> "vierthousanddertig"
|
83
|
+
=> "fyra tusen trettio"
|
58
84
|
|
59
85
|
1000100.to_words
|
60
86
|
=> "one million one hundred"
|
87
|
+
=> "un millón cien"
|
61
88
|
=> "один миллион сто"
|
62
89
|
=> "un million cent"
|
63
90
|
=> "один мiльйон сто"
|
91
|
+
=> "egymillió-egyszáz"
|
64
92
|
=> "bir milyon bir yüz"
|
65
93
|
=> "uno milione 1 cento"
|
66
94
|
=> "één miljoen honderd"
|
95
|
+
=> "en miljoner en hundra"
|
67
96
|
|
68
97
|
1000000000000000000000000000000000.to_words
|
69
98
|
=> "one decillion"
|
99
|
+
=> "un quintillardo"
|
70
100
|
=> "один дециллион"
|
71
101
|
=> "un quintilliard"
|
72
102
|
=> "один децильйон"
|
103
|
+
=> "egykvintilliárd"
|
73
104
|
=> "bir desilyon"
|
74
105
|
=> "uno decillion"
|
75
106
|
=> "één decillion"
|
107
|
+
=> "en decillion"
|
76
108
|
|
77
109
|
[1, 2, 3].to_words
|
78
110
|
=> ["one", "two", "three"]
|
111
|
+
=> ["uno", "dos", "tres"]
|
79
112
|
=> ["один", "два", "три"]
|
80
113
|
=> ["un", "deux", "trois"]
|
114
|
+
=> ["egy", "kettő", "három"]
|
81
115
|
|
82
116
|
[11, 22, 133].to_words
|
83
117
|
=> ["eleven", "twenty-two", "one hundred thirty-three"]
|
118
|
+
=> ["once", "veintidos", "ciento treinta y tres"]
|
84
119
|
=> ["одиннадцать", "двадцать два", "сто тридцать три"]
|
85
120
|
=> ["onze", "vingt-deux", "cent trente-trois"]
|
86
121
|
=> ["одинадцять", "двадцять два", "сто тридцять три"]
|
122
|
+
=> ["tizenegy", "huszonkettő", "egyszázharminchárom"]
|
87
123
|
=> ["on bir", "yirmi iki", "bir yüz otuz üç"]
|
88
124
|
=> ["undici", "ventidue", "1 cento trentatre"]
|
89
125
|
=> ["elf", "tweeentwintig", "honderddrieendertig"]
|
126
|
+
=> ["elva", "tjugo-två", "en hundra trettio-tre"]
|
127
|
+
|
128
|
+
21.77.to_words
|
129
|
+
=> "twenty-one and seventy-seven hundredths"
|
130
|
+
=> "двадцать одна целая и семьдесят семь сотых"
|
131
|
+
=> "двадцять одна цiла i сiмдесят сiм сотих"
|
132
|
+
=> "huszonegy egész hetvenhét század"
|
133
|
+
|
134
|
+
== Language options / Языковые опции
|
135
|
+
|
136
|
+
* English
|
137
|
+
|
138
|
+
Ordinal form: (ordinal: [true || false])
|
139
|
+
|
140
|
+
I18n.with_locale(:en) { 21.to_words ordinal: true }
|
141
|
+
=> "twenty-first"
|
142
|
+
|
143
|
+
Remove hyphen between tens and ones: (remove_hyphen: [true || false])
|
144
|
+
|
145
|
+
I18n.with_locale(:en) { 21.to_words remove_hyphen: true }
|
146
|
+
=> "twenty one"
|
147
|
+
|
148
|
+
Add 'and' between hundreds and tens: (hundreds_with_union: [true || false])
|
149
|
+
|
150
|
+
I18n.with_locale(:en) { 111.to_words hundreds_with_union: true }
|
151
|
+
=> "one hundred and eleven"
|
152
|
+
|
153
|
+
Remove 'zero' from integral part of float: (remove_zero: [true || false])
|
154
|
+
|
155
|
+
I18n.with_locale(:en) { 0.7.to_words remove_zero: true }
|
156
|
+
=> "seven tenths"
|
157
|
+
|
158
|
+
* Russian
|
159
|
+
|
160
|
+
Change gender form: (gender: [:female || :male || :neuter])
|
161
|
+
|
162
|
+
I18n.with_locale(:ru) { 1001.to_words gender: :neuter }
|
163
|
+
=> "одна тысяча одно"
|
164
|
+
|
165
|
+
* Ukranian
|
166
|
+
|
167
|
+
Change gender form: (gender: [:female || :male || :neuter])
|
168
|
+
|
169
|
+
I18n.with_locale(:ru) { 1001.to_words gender: :neuter }
|
170
|
+
=> "одна тисяча одне"
|
171
|
+
|
172
|
+
* Hungarian
|
173
|
+
|
174
|
+
Ordinal form: (ordinal: [true || false])
|
175
|
+
|
176
|
+
I18n.with_locale(:hu) { 21.to_words ordinal: true }
|
177
|
+
=> "huszonegyedik"
|
90
178
|
|
91
179
|
== Requirements / Требования / Configuration Requise
|
92
180
|
|
@@ -115,3 +203,4 @@ Send a pull request. Bonus points for topic branches.
|
|
115
203
|
* Daniel Doubrovkine (link:http://github.com/dblock)
|
116
204
|
* Sergey Shkirando (mailto:shkirando.s@yandex.ru)
|
117
205
|
* Ulrich Sossou (Github[http://github.com/sorich87], {Personal Page}[http://ulrichsossou.com/])
|
206
|
+
* eLod (link:http://github.com/eLod)
|
data/lib/numbers_and_words.rb
CHANGED
@@ -2,12 +2,13 @@ require 'rubygems'
|
|
2
2
|
require 'i18n'
|
3
3
|
require 'i18n/backend/pluralization'
|
4
4
|
require 'active_support/inflector'
|
5
|
+
require 'active_support/core_ext/object'
|
5
6
|
|
6
|
-
require 'numbers_and_words/
|
7
|
+
require 'numbers_and_words/translations'
|
7
8
|
require 'numbers_and_words/strategies'
|
8
|
-
require 'numbers_and_words/
|
9
|
-
require 'numbers_and_words/figures_array'
|
9
|
+
require 'numbers_and_words/helper_classes'
|
10
10
|
require 'numbers_and_words/core_ext'
|
11
|
+
require 'numbers_and_words/wrappers'
|
11
12
|
require 'numbers_and_words/i18n'
|
12
13
|
require 'numbers_and_words/version'
|
13
14
|
|
@@ -1,12 +1,5 @@
|
|
1
1
|
class Integer
|
2
|
-
|
3
|
-
|
4
|
-
to_figures_array.to_words NumbersAndWords::Strategies::Base.factory
|
5
|
-
end
|
6
|
-
|
7
|
-
private
|
8
|
-
|
9
|
-
def to_figures_array
|
10
|
-
to_s.split(//).map(&:to_i).to_figures
|
2
|
+
def to_words options = {}
|
3
|
+
NumbersAndWords::Wrappers::Integer.new(self).to_words options
|
11
4
|
end
|
12
5
|
end
|
@@ -0,0 +1,81 @@
|
|
1
|
+
module NumbersAndWords
|
2
|
+
module ArrayExtensions
|
3
|
+
module Helpers
|
4
|
+
MICRO_CAPACITY_SHIFT = 2
|
5
|
+
FIGURES_IN_CAPACITY = 3
|
6
|
+
THOUSAND_CAPACITY = 1
|
7
|
+
ONES_SHIFT = 1
|
8
|
+
|
9
|
+
def capacity_length
|
10
|
+
length - ONES_SHIFT
|
11
|
+
end
|
12
|
+
|
13
|
+
def capacity_count
|
14
|
+
count = capacity_length / FIGURES_IN_CAPACITY
|
15
|
+
0 == count ? nil : count
|
16
|
+
end
|
17
|
+
|
18
|
+
def figures_array_in_capacity capacity
|
19
|
+
self[capacity * FIGURES_IN_CAPACITY, FIGURES_IN_CAPACITY]
|
20
|
+
end
|
21
|
+
|
22
|
+
def number_in_capacity capacity
|
23
|
+
figures_array_in_capacity(capacity).reverse.join.to_i
|
24
|
+
end
|
25
|
+
|
26
|
+
def is_a_thousand_capacity? capacity
|
27
|
+
THOUSAND_CAPACITY == capacity
|
28
|
+
end
|
29
|
+
|
30
|
+
def ones
|
31
|
+
self[0].to_i if 0 < self[0].to_i
|
32
|
+
end
|
33
|
+
|
34
|
+
def teens
|
35
|
+
tens_with_ones if 1 == tens
|
36
|
+
end
|
37
|
+
|
38
|
+
def tens
|
39
|
+
self[1].to_i if self[1] && 0 < self[1].to_i
|
40
|
+
end
|
41
|
+
|
42
|
+
def tens_with_ones
|
43
|
+
[ones, tens] if ones && tens
|
44
|
+
end
|
45
|
+
|
46
|
+
def hundreds
|
47
|
+
self[2].to_i if 0 < self[2].to_i
|
48
|
+
end
|
49
|
+
|
50
|
+
def sub_capacity
|
51
|
+
capacity_length % FIGURES_IN_CAPACITY
|
52
|
+
end
|
53
|
+
|
54
|
+
def fraction_index
|
55
|
+
index '.'
|
56
|
+
end
|
57
|
+
|
58
|
+
def fraction_capacity
|
59
|
+
[fraction_capacity_count, fraction_sub_capacity]
|
60
|
+
end
|
61
|
+
|
62
|
+
def fraction_capacity_count
|
63
|
+
capacity_count.nil? ? sub_capacity : capacity_count + MICRO_CAPACITY_SHIFT
|
64
|
+
end
|
65
|
+
|
66
|
+
def fraction_sub_capacity
|
67
|
+
sub_capacity unless capacity_count.nil?
|
68
|
+
end
|
69
|
+
|
70
|
+
def ordinal_index
|
71
|
+
index { |figure| figure != 0 }
|
72
|
+
end
|
73
|
+
|
74
|
+
def ordinal_capacity
|
75
|
+
count = ordinal_index / FIGURES_IN_CAPACITY
|
76
|
+
0 == count ? nil : count
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module NumbersAndWords
|
2
|
+
module ArrayExtensions
|
3
|
+
module Validations
|
4
|
+
#VALID_CHARACTERS = ("0".."9").to_a.push(".").freeze
|
5
|
+
|
6
|
+
def validate_figure_array!
|
7
|
+
#if invalid_characters.any?
|
8
|
+
# invalid = invalid_characters.uniq.join ', '
|
9
|
+
# raise "Figures may contain only numbers and `.` (invalid characters: #{invalid})."
|
10
|
+
#end
|
11
|
+
#raise "Figures may contain only 1 `.` (#{count '.'} found)." if count(".") > 1
|
12
|
+
end
|
13
|
+
|
14
|
+
#def invalid_characters
|
15
|
+
# reject { |character| VALID_CHARACTERS.include? character }
|
16
|
+
#end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'numbers_and_words/helper_classes/array_extensions/helpers'
|
2
|
+
require 'numbers_and_words/helper_classes/array_extensions/validations'
|
3
|
+
|
4
|
+
module NumbersAndWords
|
5
|
+
class FiguresArray < Array
|
6
|
+
include ArrayExtensions::Helpers
|
7
|
+
include ArrayExtensions::Validations
|
8
|
+
|
9
|
+
def to_words options = {}
|
10
|
+
validate_figure_array!
|
11
|
+
Strategies.figures_converter.new(self, options).run
|
12
|
+
end
|
13
|
+
|
14
|
+
def reverse
|
15
|
+
super.to_figures
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
require 'numbers_and_words/helper_classes/array_extensions/helpers'
|
2
|
+
require 'numbers_and_words/helper_classes/array_extensions/validations'
|
3
|
+
|
4
|
+
module NumbersAndWords
|
5
|
+
class WordsArray < Array
|
6
|
+
|
7
|
+
def join options = {}
|
8
|
+
Strategies.array_joiner.new(self.to_a, options).run
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
@@ -5,3 +5,51 @@ en:
|
|
5
5
|
tens: [zero, ten, twenty, thirty, forty, fifty, sixty, seventy, eighty, ninety]
|
6
6
|
hundreds: hundred
|
7
7
|
mega: [ones, thousand, million, billion, trillion, quadrillion, quintillion, sextillion, septillion, octillion, nonillion, decillion]
|
8
|
+
ordinal:
|
9
|
+
ones: [zeroth, first, second, third, fourth, fifth, sixth, seventh, eighth, ninth]
|
10
|
+
teens: [tenth, eleventh, twelfth, thirteenth, fourteenth, fifteenth, sixteenth, seventeenth, eighteenth, nineteenth]
|
11
|
+
tens: [zeroth, tenth, twentieth, thirtieth, fortieth, fiftieth, sixtieth, seventieth, eightieth, ninetieth]
|
12
|
+
hundreds: hundredth
|
13
|
+
mega: [zeroth, thousandth, millionth, billionth, trillionth, quadrillionth, quintillionth, sextillionth, septillionth, octillionth, nonillionth, decillionth]
|
14
|
+
fraction_separator: and
|
15
|
+
micro: [_, tenths, hundredths, thousandths, millionths, billionths, trillionths, quadrillionths, quintillionths, sextillionths, septillionths, octillionths, nonillionths, decillionths]
|
16
|
+
tenths:
|
17
|
+
one: tenth
|
18
|
+
other: tenths
|
19
|
+
hundredths:
|
20
|
+
one: hundredth
|
21
|
+
other: hundredths
|
22
|
+
thousandths:
|
23
|
+
one: thousandth
|
24
|
+
other: thousandths
|
25
|
+
millionths:
|
26
|
+
one: millionth
|
27
|
+
other: millionths
|
28
|
+
billionths:
|
29
|
+
one: billionth
|
30
|
+
other: billionths
|
31
|
+
trillionths:
|
32
|
+
one: trillionth
|
33
|
+
other: trillionths
|
34
|
+
quadrillionths:
|
35
|
+
one: quadrillionth
|
36
|
+
other: quadrillionths
|
37
|
+
quintillionths:
|
38
|
+
one: quintillionth
|
39
|
+
other: quintillionths
|
40
|
+
sextillionths:
|
41
|
+
one: sextillionth
|
42
|
+
other: sextillionths
|
43
|
+
septillionths:
|
44
|
+
one: septillionth
|
45
|
+
other: septillionths
|
46
|
+
octillionths:
|
47
|
+
one: octillionth
|
48
|
+
other: octillionths
|
49
|
+
nonillionths:
|
50
|
+
one: nonillionth
|
51
|
+
other: nonillionths
|
52
|
+
decillionths:
|
53
|
+
one: decillionth
|
54
|
+
other: decillionths
|
55
|
+
union: and
|