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.
Files changed (116) hide show
  1. checksums.yaml +15 -0
  2. data/README.rdoc +90 -1
  3. data/lib/numbers_and_words.rb +4 -3
  4. data/lib/numbers_and_words/core_ext.rb +1 -0
  5. data/lib/numbers_and_words/core_ext/array.rb +1 -1
  6. data/lib/numbers_and_words/core_ext/float.rb +5 -0
  7. data/lib/numbers_and_words/core_ext/integer.rb +2 -9
  8. data/lib/numbers_and_words/helper_classes.rb +2 -0
  9. data/lib/numbers_and_words/helper_classes/array_extensions/helpers.rb +81 -0
  10. data/lib/numbers_and_words/helper_classes/array_extensions/validations.rb +19 -0
  11. data/lib/numbers_and_words/helper_classes/figures_array.rb +18 -0
  12. data/lib/numbers_and_words/helper_classes/words_array.rb +11 -0
  13. data/lib/numbers_and_words/i18n/locales/numbers.en.yml +48 -0
  14. data/lib/numbers_and_words/i18n/locales/numbers.es.yml +15 -0
  15. data/lib/numbers_and_words/i18n/locales/numbers.hu.yml +16 -0
  16. data/lib/numbers_and_words/i18n/locales/numbers.ru.yml +27 -3
  17. data/lib/numbers_and_words/i18n/locales/numbers.se.yml +7 -0
  18. data/lib/numbers_and_words/i18n/locales/numbers.ua.yml +14 -2
  19. data/lib/numbers_and_words/i18n/pluralization.rb +1 -0
  20. data/lib/numbers_and_words/i18n/plurals/es.rb +11 -0
  21. data/lib/numbers_and_words/strategies.rb +16 -11
  22. data/lib/numbers_and_words/strategies/array_joiner.rb +31 -0
  23. data/lib/numbers_and_words/strategies/figures_converter.rb +33 -0
  24. data/lib/numbers_and_words/strategies/figures_converter/decorators.rb +39 -0
  25. data/lib/numbers_and_words/strategies/figures_converter/decorators/base.rb +18 -0
  26. data/lib/numbers_and_words/strategies/figures_converter/decorators/en.rb +3 -0
  27. data/lib/numbers_and_words/strategies/figures_converter/decorators/en/base.rb +12 -0
  28. data/lib/numbers_and_words/strategies/figures_converter/decorators/en/fractional.rb +38 -0
  29. data/lib/numbers_and_words/strategies/figures_converter/decorators/en/integral.rb +12 -0
  30. data/lib/numbers_and_words/strategies/figures_converter/decorators/hu.rb +3 -0
  31. data/lib/numbers_and_words/strategies/figures_converter/decorators/hu/base.rb +12 -0
  32. data/lib/numbers_and_words/strategies/figures_converter/decorators/hu/fractional.rb +38 -0
  33. data/lib/numbers_and_words/strategies/figures_converter/decorators/hu/integral.rb +12 -0
  34. data/lib/numbers_and_words/strategies/figures_converter/decorators/ru.rb +3 -0
  35. data/lib/numbers_and_words/strategies/figures_converter/decorators/ru/base.rb +12 -0
  36. data/lib/numbers_and_words/strategies/figures_converter/decorators/ru/fractional.rb +39 -0
  37. data/lib/numbers_and_words/strategies/figures_converter/decorators/ru/integral.rb +27 -0
  38. data/lib/numbers_and_words/strategies/figures_converter/decorators/ua.rb +3 -0
  39. data/lib/numbers_and_words/strategies/figures_converter/decorators/ua/base.rb +12 -0
  40. data/lib/numbers_and_words/strategies/figures_converter/decorators/ua/fractional.rb +39 -0
  41. data/lib/numbers_and_words/strategies/figures_converter/decorators/ua/integral.rb +27 -0
  42. data/lib/numbers_and_words/strategies/figures_converter/languages.rb +39 -0
  43. data/lib/numbers_and_words/strategies/figures_converter/languages/base.rb +29 -0
  44. data/lib/numbers_and_words/strategies/figures_converter/languages/en.rb +48 -0
  45. data/lib/numbers_and_words/strategies/figures_converter/languages/es.rb +37 -0
  46. data/lib/numbers_and_words/strategies/figures_converter/languages/families/base.rb +77 -0
  47. data/lib/numbers_and_words/strategies/figures_converter/languages/families/cyrillic.rb +34 -0
  48. data/lib/numbers_and_words/strategies/figures_converter/languages/families/helpers.rb +36 -0
  49. data/lib/numbers_and_words/strategies/figures_converter/languages/families/latin.rb +13 -0
  50. data/lib/numbers_and_words/strategies/figures_converter/languages/fr.rb +37 -0
  51. data/lib/numbers_and_words/strategies/figures_converter/languages/hu.rb +63 -0
  52. data/lib/numbers_and_words/strategies/figures_converter/languages/it.rb +11 -0
  53. data/lib/numbers_and_words/strategies/figures_converter/languages/nl.rb +26 -0
  54. data/lib/numbers_and_words/strategies/figures_converter/languages/ru.rb +11 -0
  55. data/lib/numbers_and_words/strategies/figures_converter/languages/se.rb +11 -0
  56. data/lib/numbers_and_words/strategies/figures_converter/languages/tr.rb +11 -0
  57. data/lib/numbers_and_words/strategies/figures_converter/languages/ua.rb +11 -0
  58. data/lib/numbers_and_words/strategies/figures_converter/options.rb +41 -0
  59. data/lib/numbers_and_words/strategies/figures_converter/options/en.rb +4 -0
  60. data/lib/numbers_and_words/strategies/figures_converter/options/en/hundreds_with_union.rb +33 -0
  61. data/lib/numbers_and_words/strategies/figures_converter/options/en/ordinal.rb +60 -0
  62. data/lib/numbers_and_words/strategies/figures_converter/options/en/remove_hyphen.rb +29 -0
  63. data/lib/numbers_and_words/strategies/figures_converter/options/en/remove_zero.rb +29 -0
  64. data/lib/numbers_and_words/strategies/figures_converter/options/hu.rb +1 -0
  65. data/lib/numbers_and_words/strategies/figures_converter/options/hu/ordinal.rb +60 -0
  66. data/lib/numbers_and_words/strategies/figures_converter/options/ru.rb +1 -0
  67. data/lib/numbers_and_words/strategies/figures_converter/options/ru/gender.rb +28 -0
  68. data/lib/numbers_and_words/strategies/figures_converter/options/ua.rb +1 -0
  69. data/lib/numbers_and_words/strategies/figures_converter/options/ua/gender.rb +28 -0
  70. data/lib/numbers_and_words/translations.rb +25 -0
  71. data/lib/numbers_and_words/{translations_helpers → translations}/base.rb +2 -2
  72. data/lib/numbers_and_words/translations/en.rb +8 -0
  73. data/lib/numbers_and_words/translations/es.rb +37 -0
  74. data/lib/numbers_and_words/translations/extensions/fraction_significance.rb +25 -0
  75. data/lib/numbers_and_words/translations/families/base.rb +33 -0
  76. data/lib/numbers_and_words/translations/families/cyrillic.rb +29 -0
  77. data/lib/numbers_and_words/translations/families/latin.rb +23 -0
  78. data/lib/numbers_and_words/translations/fr.rb +29 -0
  79. data/lib/numbers_and_words/translations/hu.rb +26 -0
  80. data/lib/numbers_and_words/translations/it.rb +15 -0
  81. data/lib/numbers_and_words/translations/nl.rb +15 -0
  82. data/lib/numbers_and_words/translations/ru.rb +25 -0
  83. data/lib/numbers_and_words/translations/se.rb +11 -0
  84. data/lib/numbers_and_words/translations/tr.rb +11 -0
  85. data/lib/numbers_and_words/translations/ua.rb +21 -0
  86. data/lib/numbers_and_words/version.rb +1 -1
  87. data/lib/numbers_and_words/wrappers.rb +2 -0
  88. data/lib/numbers_and_words/wrappers/float.rb +60 -0
  89. data/lib/numbers_and_words/wrappers/integer.rb +21 -0
  90. metadata +81 -44
  91. data/lib/numbers_and_words/array_additions.rb +0 -2
  92. data/lib/numbers_and_words/array_additions/helpers.rb +0 -44
  93. data/lib/numbers_and_words/array_additions/validations.rb +0 -9
  94. data/lib/numbers_and_words/figures_array.rb +0 -15
  95. data/lib/numbers_and_words/strategies/base.rb +0 -18
  96. data/lib/numbers_and_words/strategies/en.rb +0 -8
  97. data/lib/numbers_and_words/strategies/families/base.rb +0 -71
  98. data/lib/numbers_and_words/strategies/families/cyrillic.rb +0 -18
  99. data/lib/numbers_and_words/strategies/families/latin.rb +0 -9
  100. data/lib/numbers_and_words/strategies/fr.rb +0 -32
  101. data/lib/numbers_and_words/strategies/it.rb +0 -8
  102. data/lib/numbers_and_words/strategies/nl.rb +0 -23
  103. data/lib/numbers_and_words/strategies/ru.rb +0 -8
  104. data/lib/numbers_and_words/strategies/tr.rb +0 -8
  105. data/lib/numbers_and_words/strategies/ua.rb +0 -8
  106. data/lib/numbers_and_words/translations_helpers.rb +0 -11
  107. data/lib/numbers_and_words/translations_helpers/en.rb +0 -12
  108. data/lib/numbers_and_words/translations_helpers/families/base.rb +0 -30
  109. data/lib/numbers_and_words/translations_helpers/families/cyrillic.rb +0 -28
  110. data/lib/numbers_and_words/translations_helpers/families/latin.rb +0 -23
  111. data/lib/numbers_and_words/translations_helpers/fr.rb +0 -34
  112. data/lib/numbers_and_words/translations_helpers/it.rb +0 -16
  113. data/lib/numbers_and_words/translations_helpers/nl.rb +0 -18
  114. data/lib/numbers_and_words/translations_helpers/ru.rb +0 -8
  115. data/lib/numbers_and_words/translations_helpers/tr.rb +0 -8
  116. data/lib/numbers_and_words/translations_helpers/ua.rb +0 -8
@@ -0,0 +1,2 @@
1
+ require 'numbers_and_words/wrappers/integer'
2
+ require 'numbers_and_words/wrappers/float'
@@ -0,0 +1,60 @@
1
+ module NumbersAndWords
2
+ module Wrappers
3
+ class Float
4
+ attr_accessor :number
5
+
6
+ def initialize number
7
+ @number = number
8
+ end
9
+
10
+ def to_words options = {}
11
+ words = []
12
+ words << integral_part_with(options) if integral_part_with(options).present?
13
+ words << fractional_part_with(options) unless fractional_part_is_nil?
14
+ NumbersAndWords::WordsArray.new(words).join options
15
+ end
16
+
17
+ private
18
+
19
+ def parts
20
+ number.to_s.split '.'
21
+ end
22
+
23
+ def exponential?
24
+ number.to_s =~ /[eE]{1}\+/
25
+ end
26
+
27
+ def integral_part
28
+ parts.first
29
+ end
30
+
31
+ def fractional_part
32
+ parts.last
33
+ end
34
+
35
+ def integral_part_with options
36
+ integral_part.to_i.to_words options.merge(integral_options)
37
+ end
38
+
39
+ def fractional_part_with options
40
+ fractional_part.to_i.to_words options.merge(fractional_options)
41
+ end
42
+
43
+ def integral_options
44
+ {:integral => {}}
45
+ end
46
+
47
+ def fractional_options
48
+ {:fractional => {:length => fractional_part.length}}
49
+ end
50
+
51
+ def integral_part_is_nil?
52
+ 0 == integral_part.to_i
53
+ end
54
+
55
+ def fractional_part_is_nil?
56
+ 0 == fractional_part.to_i
57
+ end
58
+ end
59
+ end
60
+ end
@@ -0,0 +1,21 @@
1
+ module NumbersAndWords
2
+ module Wrappers
3
+ class Integer
4
+ attr_accessor :number
5
+
6
+ def initialize number
7
+ @number = number
8
+ end
9
+
10
+ def to_words options = {}
11
+ to_figures_array.to_words options
12
+ end
13
+
14
+ private
15
+
16
+ def to_figures_array
17
+ number.to_s.split(//).map(&:to_i).to_figures
18
+ end
19
+ end
20
+ end
21
+ end
metadata CHANGED
@@ -1,20 +1,18 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: numbers_and_words
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
5
- prerelease:
4
+ version: 0.6.0
6
5
  platform: ruby
7
6
  authors:
8
7
  - Kirill Lazarev
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2012-10-19 00:00:00.000000000 Z
11
+ date: 2013-03-25 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: i18n
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
17
  - - ! '>='
20
18
  - !ruby/object:Gem::Version
@@ -22,7 +20,6 @@ dependencies:
22
20
  type: :runtime
23
21
  prerelease: false
24
22
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
23
  requirements:
27
24
  - - ! '>='
28
25
  - !ruby/object:Gem::Version
@@ -30,7 +27,6 @@ dependencies:
30
27
  - !ruby/object:Gem::Dependency
31
28
  name: activesupport
32
29
  requirement: !ruby/object:Gem::Requirement
33
- none: false
34
30
  requirements:
35
31
  - - ! '>='
36
32
  - !ruby/object:Gem::Version
@@ -38,7 +34,6 @@ dependencies:
38
34
  type: :runtime
39
35
  prerelease: false
40
36
  version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
37
  requirements:
43
38
  - - ! '>='
44
39
  - !ruby/object:Gem::Version
@@ -46,7 +41,6 @@ dependencies:
46
41
  - !ruby/object:Gem::Dependency
47
42
  name: rake
48
43
  requirement: !ruby/object:Gem::Requirement
49
- none: false
50
44
  requirements:
51
45
  - - ! '>='
52
46
  - !ruby/object:Gem::Version
@@ -54,7 +48,6 @@ dependencies:
54
48
  type: :development
55
49
  prerelease: false
56
50
  version_requirements: !ruby/object:Gem::Requirement
57
- none: false
58
51
  requirements:
59
52
  - - ! '>='
60
53
  - !ruby/object:Gem::Version
@@ -62,7 +55,6 @@ dependencies:
62
55
  - !ruby/object:Gem::Dependency
63
56
  name: jeweler
64
57
  requirement: !ruby/object:Gem::Requirement
65
- none: false
66
58
  requirements:
67
59
  - - ! '>='
68
60
  - !ruby/object:Gem::Version
@@ -70,7 +62,6 @@ dependencies:
70
62
  type: :development
71
63
  prerelease: false
72
64
  version_requirements: !ruby/object:Gem::Requirement
73
- none: false
74
65
  requirements:
75
66
  - - ! '>='
76
67
  - !ruby/object:Gem::Version
@@ -84,79 +75,125 @@ extra_rdoc_files:
84
75
  - README.rdoc
85
76
  files:
86
77
  - lib/numbers_and_words.rb
87
- - lib/numbers_and_words/array_additions.rb
88
- - lib/numbers_and_words/array_additions/helpers.rb
89
- - lib/numbers_and_words/array_additions/validations.rb
90
78
  - lib/numbers_and_words/core_ext.rb
91
79
  - lib/numbers_and_words/core_ext/array.rb
80
+ - lib/numbers_and_words/core_ext/float.rb
92
81
  - lib/numbers_and_words/core_ext/integer.rb
93
- - lib/numbers_and_words/figures_array.rb
82
+ - lib/numbers_and_words/helper_classes.rb
83
+ - lib/numbers_and_words/helper_classes/array_extensions/helpers.rb
84
+ - lib/numbers_and_words/helper_classes/array_extensions/validations.rb
85
+ - lib/numbers_and_words/helper_classes/figures_array.rb
86
+ - lib/numbers_and_words/helper_classes/words_array.rb
94
87
  - lib/numbers_and_words/i18n.rb
95
88
  - lib/numbers_and_words/i18n/initialization.rb
96
89
  - lib/numbers_and_words/i18n/locales/numbers.en.yml
90
+ - lib/numbers_and_words/i18n/locales/numbers.es.yml
97
91
  - lib/numbers_and_words/i18n/locales/numbers.fr.yml
92
+ - lib/numbers_and_words/i18n/locales/numbers.hu.yml
98
93
  - lib/numbers_and_words/i18n/locales/numbers.it.yml
99
94
  - lib/numbers_and_words/i18n/locales/numbers.nl.yml
100
95
  - lib/numbers_and_words/i18n/locales/numbers.ru.yml
96
+ - lib/numbers_and_words/i18n/locales/numbers.se.yml
101
97
  - lib/numbers_and_words/i18n/locales/numbers.tr.yml
102
98
  - lib/numbers_and_words/i18n/locales/numbers.ua.yml
103
99
  - lib/numbers_and_words/i18n/pluralization.rb
100
+ - lib/numbers_and_words/i18n/plurals/es.rb
104
101
  - lib/numbers_and_words/i18n/plurals/fr.rb
105
102
  - lib/numbers_and_words/i18n/plurals/plurals.rb
106
103
  - lib/numbers_and_words/i18n/plurals/ru.rb
107
104
  - lib/numbers_and_words/i18n/plurals/ua.rb
108
105
  - lib/numbers_and_words/strategies.rb
109
- - lib/numbers_and_words/strategies/base.rb
110
- - lib/numbers_and_words/strategies/en.rb
111
- - lib/numbers_and_words/strategies/families/base.rb
112
- - lib/numbers_and_words/strategies/families/cyrillic.rb
113
- - lib/numbers_and_words/strategies/families/latin.rb
114
- - lib/numbers_and_words/strategies/fr.rb
115
- - lib/numbers_and_words/strategies/it.rb
116
- - lib/numbers_and_words/strategies/nl.rb
117
- - lib/numbers_and_words/strategies/ru.rb
118
- - lib/numbers_and_words/strategies/tr.rb
119
- - lib/numbers_and_words/strategies/ua.rb
120
- - lib/numbers_and_words/translations_helpers.rb
121
- - lib/numbers_and_words/translations_helpers/base.rb
122
- - lib/numbers_and_words/translations_helpers/en.rb
123
- - lib/numbers_and_words/translations_helpers/families/base.rb
124
- - lib/numbers_and_words/translations_helpers/families/cyrillic.rb
125
- - lib/numbers_and_words/translations_helpers/families/latin.rb
126
- - lib/numbers_and_words/translations_helpers/fr.rb
127
- - lib/numbers_and_words/translations_helpers/it.rb
128
- - lib/numbers_and_words/translations_helpers/nl.rb
129
- - lib/numbers_and_words/translations_helpers/ru.rb
130
- - lib/numbers_and_words/translations_helpers/tr.rb
131
- - lib/numbers_and_words/translations_helpers/ua.rb
106
+ - lib/numbers_and_words/strategies/array_joiner.rb
107
+ - lib/numbers_and_words/strategies/figures_converter.rb
108
+ - lib/numbers_and_words/strategies/figures_converter/decorators.rb
109
+ - lib/numbers_and_words/strategies/figures_converter/decorators/base.rb
110
+ - lib/numbers_and_words/strategies/figures_converter/decorators/en.rb
111
+ - lib/numbers_and_words/strategies/figures_converter/decorators/en/base.rb
112
+ - lib/numbers_and_words/strategies/figures_converter/decorators/en/fractional.rb
113
+ - lib/numbers_and_words/strategies/figures_converter/decorators/en/integral.rb
114
+ - lib/numbers_and_words/strategies/figures_converter/decorators/hu.rb
115
+ - lib/numbers_and_words/strategies/figures_converter/decorators/hu/base.rb
116
+ - lib/numbers_and_words/strategies/figures_converter/decorators/hu/fractional.rb
117
+ - lib/numbers_and_words/strategies/figures_converter/decorators/hu/integral.rb
118
+ - lib/numbers_and_words/strategies/figures_converter/decorators/ru.rb
119
+ - lib/numbers_and_words/strategies/figures_converter/decorators/ru/base.rb
120
+ - lib/numbers_and_words/strategies/figures_converter/decorators/ru/fractional.rb
121
+ - lib/numbers_and_words/strategies/figures_converter/decorators/ru/integral.rb
122
+ - lib/numbers_and_words/strategies/figures_converter/decorators/ua.rb
123
+ - lib/numbers_and_words/strategies/figures_converter/decorators/ua/base.rb
124
+ - lib/numbers_and_words/strategies/figures_converter/decorators/ua/fractional.rb
125
+ - lib/numbers_and_words/strategies/figures_converter/decorators/ua/integral.rb
126
+ - lib/numbers_and_words/strategies/figures_converter/languages.rb
127
+ - lib/numbers_and_words/strategies/figures_converter/languages/base.rb
128
+ - lib/numbers_and_words/strategies/figures_converter/languages/en.rb
129
+ - lib/numbers_and_words/strategies/figures_converter/languages/es.rb
130
+ - lib/numbers_and_words/strategies/figures_converter/languages/families/base.rb
131
+ - lib/numbers_and_words/strategies/figures_converter/languages/families/cyrillic.rb
132
+ - lib/numbers_and_words/strategies/figures_converter/languages/families/helpers.rb
133
+ - lib/numbers_and_words/strategies/figures_converter/languages/families/latin.rb
134
+ - lib/numbers_and_words/strategies/figures_converter/languages/fr.rb
135
+ - lib/numbers_and_words/strategies/figures_converter/languages/hu.rb
136
+ - lib/numbers_and_words/strategies/figures_converter/languages/it.rb
137
+ - lib/numbers_and_words/strategies/figures_converter/languages/nl.rb
138
+ - lib/numbers_and_words/strategies/figures_converter/languages/ru.rb
139
+ - lib/numbers_and_words/strategies/figures_converter/languages/se.rb
140
+ - lib/numbers_and_words/strategies/figures_converter/languages/tr.rb
141
+ - lib/numbers_and_words/strategies/figures_converter/languages/ua.rb
142
+ - lib/numbers_and_words/strategies/figures_converter/options.rb
143
+ - lib/numbers_and_words/strategies/figures_converter/options/en.rb
144
+ - lib/numbers_and_words/strategies/figures_converter/options/en/hundreds_with_union.rb
145
+ - lib/numbers_and_words/strategies/figures_converter/options/en/ordinal.rb
146
+ - lib/numbers_and_words/strategies/figures_converter/options/en/remove_hyphen.rb
147
+ - lib/numbers_and_words/strategies/figures_converter/options/en/remove_zero.rb
148
+ - lib/numbers_and_words/strategies/figures_converter/options/hu.rb
149
+ - lib/numbers_and_words/strategies/figures_converter/options/hu/ordinal.rb
150
+ - lib/numbers_and_words/strategies/figures_converter/options/ru.rb
151
+ - lib/numbers_and_words/strategies/figures_converter/options/ru/gender.rb
152
+ - lib/numbers_and_words/strategies/figures_converter/options/ua.rb
153
+ - lib/numbers_and_words/strategies/figures_converter/options/ua/gender.rb
154
+ - lib/numbers_and_words/translations.rb
155
+ - lib/numbers_and_words/translations/base.rb
156
+ - lib/numbers_and_words/translations/en.rb
157
+ - lib/numbers_and_words/translations/es.rb
158
+ - lib/numbers_and_words/translations/extensions/fraction_significance.rb
159
+ - lib/numbers_and_words/translations/families/base.rb
160
+ - lib/numbers_and_words/translations/families/cyrillic.rb
161
+ - lib/numbers_and_words/translations/families/latin.rb
162
+ - lib/numbers_and_words/translations/fr.rb
163
+ - lib/numbers_and_words/translations/hu.rb
164
+ - lib/numbers_and_words/translations/it.rb
165
+ - lib/numbers_and_words/translations/nl.rb
166
+ - lib/numbers_and_words/translations/ru.rb
167
+ - lib/numbers_and_words/translations/se.rb
168
+ - lib/numbers_and_words/translations/tr.rb
169
+ - lib/numbers_and_words/translations/ua.rb
132
170
  - lib/numbers_and_words/version.rb
171
+ - lib/numbers_and_words/wrappers.rb
172
+ - lib/numbers_and_words/wrappers/float.rb
173
+ - lib/numbers_and_words/wrappers/integer.rb
133
174
  - LICENSE.txt
134
175
  - README.rdoc
135
176
  homepage: http://github.com/kslazarev/numbers_and_words
136
177
  licenses:
137
178
  - MIT
179
+ metadata: {}
138
180
  post_install_message:
139
181
  rdoc_options: []
140
182
  require_paths:
141
183
  - lib
142
184
  required_ruby_version: !ruby/object:Gem::Requirement
143
- none: false
144
185
  requirements:
145
186
  - - ! '>='
146
187
  - !ruby/object:Gem::Version
147
188
  version: '0'
148
- segments:
149
- - 0
150
- hash: 4516807369747815083
151
189
  required_rubygems_version: !ruby/object:Gem::Requirement
152
- none: false
153
190
  requirements:
154
191
  - - ! '>='
155
192
  - !ruby/object:Gem::Version
156
193
  version: '0'
157
194
  requirements: []
158
195
  rubyforge_project:
159
- rubygems_version: 1.8.24
196
+ rubygems_version: 2.0.3
160
197
  signing_key:
161
198
  specification_version: 3
162
199
  summary: Convert numbers to words using I18N.
@@ -1,2 +0,0 @@
1
- require 'numbers_and_words/array_additions/helpers'
2
- require 'numbers_and_words/array_additions/validations'
@@ -1,44 +0,0 @@
1
- module NumbersAndWords
2
- module ArrayAdditions
3
- module Helpers
4
- THOUSAND_CAPACITY = 1
5
-
6
- def capacity_count
7
- count = (self.length.to_f / 3).ceil - 1
8
- 0 == count ? nil : count
9
- end
10
-
11
- def figures_array_in_capacity capacity
12
- self[capacity * 3, 3]
13
- end
14
-
15
- def number_in_capacity capacity
16
- figures_array_in_capacity(capacity).reverse.join.to_i
17
- end
18
-
19
- def is_a_thousand_capacity? capacity
20
- THOUSAND_CAPACITY == capacity
21
- end
22
-
23
- def ones
24
- self[0] if 0 < self[0].to_i
25
- end
26
-
27
- def teens
28
- tens_with_ones if 1 == tens
29
- end
30
-
31
- def tens
32
- self[1] if self[1] and 0 < self[1].to_i
33
- end
34
-
35
- def tens_with_ones
36
- [ones, tens] if ones and tens
37
- end
38
-
39
- def hundreds
40
- self[2] if 0 < self[2].to_i
41
- end
42
- end
43
- end
44
- end
@@ -1,9 +0,0 @@
1
- module NumbersAndWords
2
- module ArrayAdditions
3
- module Validations
4
- def validate_figure_array!
5
-
6
- end
7
- end
8
- end
9
- end
@@ -1,15 +0,0 @@
1
- module NumbersAndWords
2
- class FiguresArray < Array
3
- include NumbersAndWords::ArrayAdditions::Helpers
4
- include NumbersAndWords::ArrayAdditions::Validations
5
-
6
- def to_words strategy, options = nil
7
- validate_figure_array!
8
- strategy.convert self
9
- end
10
-
11
- def reverse
12
- super.to_figures
13
- end
14
- end
15
- end
@@ -1,18 +0,0 @@
1
- module NumbersAndWords
2
- module Strategies
3
- class Base
4
- attr_accessor :figures, :words
5
-
6
- def self.factory
7
- "NumbersAndWords::Strategies::#{::I18n.locale.to_s.titleize}".constantize.new
8
- end
9
-
10
- def convert figures
11
- @figures = figures.reverse
12
- @words = strings
13
-
14
- @words.empty? ? zero : @words.reverse.join(' ')
15
- end
16
- end
17
- end
18
- end
@@ -1,8 +0,0 @@
1
- module NumbersAndWords
2
- module Strategies
3
- class En < Base
4
- include Families::Latin
5
- include NumbersAndWords::TranslationsHelpers::En
6
- end
7
- end
8
- end
@@ -1,71 +0,0 @@
1
- module NumbersAndWords
2
- module Strategies
3
- module Families
4
- module Base
5
-
6
- private
7
-
8
- def strings
9
- if figures.capacity_count
10
- number_without_capacity_to_words + complex_number_to_words
11
- elsif figures.hundreds
12
- hundreds_number_to_words
13
- elsif figures.tens or figures.ones
14
- simple_number_to_words
15
- else
16
- []
17
- end
18
- end
19
-
20
- def complex_number_to_words
21
- (1..figures.capacity_count).map{|capacity| capacity_iteration(capacity)}.flatten
22
- end
23
-
24
- def capacity_iteration capacity
25
- words = []
26
- capacity_words = words_in_capacity(capacity)
27
- words.push(translation_megs(capacity)) unless capacity_words.empty?
28
- words + capacity_words
29
- end
30
-
31
- def words_in_capacity capacity = 0
32
- save_parent_figures do |parent_figures|
33
- @figures = parent_figures.figures_array_in_capacity(capacity)
34
- strings
35
- end
36
- end
37
-
38
- alias_method :number_without_capacity_to_words, :words_in_capacity
39
-
40
- def hundreds_number_to_words
41
- simple_number_to_words + [translation_hundreds(figures.hundreds)]
42
- end
43
-
44
- def complex_tens
45
- figures.ones ?
46
- translation_tens_with_ones(figures.tens_with_ones) :
47
- translation_tens(figures.tens)
48
- end
49
-
50
- def simple_number_to_words
51
- if figures.teens
52
- [translation_teens(figures.ones)]
53
- elsif figures.tens
54
- [complex_tens]
55
- elsif figures.ones
56
- [translation_ones(figures.ones)]
57
- else
58
- []
59
- end
60
- end
61
-
62
- def save_parent_figures
63
- parent_figures = @figures
64
- result = yield(parent_figures)
65
- @figures = parent_figures
66
- result
67
- end
68
- end
69
- end
70
- end
71
- end