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
@@ -1,18 +0,0 @@
1
- module NumbersAndWords
2
- module Strategies
3
- module Families
4
- module Cyrillic
5
- include NumbersAndWords::Strategies::Families::Base
6
-
7
- attr_accessor :current_capacity
8
-
9
- private
10
-
11
- def words_in_capacity capacity = 0
12
- @current_capacity = capacity
13
- super
14
- end
15
- end
16
- end
17
- end
18
- end
@@ -1,9 +0,0 @@
1
- module NumbersAndWords
2
- module Strategies
3
- module Families
4
- module Latin
5
- include NumbersAndWords::Strategies::Families::Base
6
- end
7
- end
8
- end
9
- end
@@ -1,32 +0,0 @@
1
- module NumbersAndWords
2
- module Strategies
3
- class Fr < Base
4
- include Families::Latin
5
- include NumbersAndWords::TranslationsHelpers::Fr
6
-
7
- private
8
-
9
- def capacity_iteration capacity
10
- words = []
11
- capacity_words = words_in_capacity(capacity)
12
- words.push(translation_megs(capacity)) unless capacity_words.empty?
13
- words += capacity_words unless is_a_thousand?(capacity) and is_a_one?(capacity_words)
14
- words
15
- end
16
-
17
- def is_a_one? capacity_words
18
- [t(:ones)[1]] == capacity_words
19
- end
20
-
21
- def is_a_thousand? capacity
22
- FiguresArray::THOUSAND_CAPACITY == capacity
23
- end
24
-
25
- def hundreds_number_to_words
26
- simple_number_to_words + [
27
- translation_hundreds(figures.hundreds, simple_number_to_words.empty?)
28
- ]
29
- end
30
- end
31
- end
32
- end
@@ -1,8 +0,0 @@
1
- module NumbersAndWords
2
- module Strategies
3
- class It < Base
4
- include Families::Latin
5
- include NumbersAndWords::TranslationsHelpers::It
6
- end
7
- end
8
- end
@@ -1,23 +0,0 @@
1
- module NumbersAndWords
2
- module Strategies
3
- class Nl < Base
4
- include Families::Latin
5
- include NumbersAndWords::TranslationsHelpers::Nl
6
-
7
- def hundreds_number_to_words
8
- [super.reverse.join]
9
- end
10
-
11
- def capacity_iteration capacity
12
- if FiguresArray::THOUSAND_CAPACITY == capacity
13
- words = []
14
- capacity_words = words_in_capacity(capacity)
15
- words.push(translation_megs(capacity)) unless capacity_words.empty?
16
- capacity_words.empty? ? [] : [capacity_words, words].join
17
- else
18
- super
19
- end
20
- end
21
- end
22
- end
23
- end
@@ -1,8 +0,0 @@
1
- module NumbersAndWords
2
- module Strategies
3
- class Ru < Base
4
- include Families::Cyrillic
5
- include NumbersAndWords::TranslationsHelpers::Ru
6
- end
7
- end
8
- end
@@ -1,8 +0,0 @@
1
- module NumbersAndWords
2
- module Strategies
3
- class Tr < Base
4
- include Families::Latin
5
- include NumbersAndWords::TranslationsHelpers::Tr
6
- end
7
- end
8
- end
@@ -1,8 +0,0 @@
1
- module NumbersAndWords
2
- module Strategies
3
- class Ua < Base
4
- include Families::Cyrillic
5
- include NumbersAndWords::TranslationsHelpers::Ua
6
- end
7
- end
8
- end
@@ -1,11 +0,0 @@
1
- require 'numbers_and_words/translations_helpers/base'
2
- require 'numbers_and_words/translations_helpers/families/base'
3
- require 'numbers_and_words/translations_helpers/families/cyrillic'
4
- require 'numbers_and_words/translations_helpers/families/latin'
5
- require 'numbers_and_words/translations_helpers/ru'
6
- require 'numbers_and_words/translations_helpers/en'
7
- require 'numbers_and_words/translations_helpers/ua'
8
- require 'numbers_and_words/translations_helpers/tr'
9
- require 'numbers_and_words/translations_helpers/fr'
10
- require 'numbers_and_words/translations_helpers/nl'
11
- require 'numbers_and_words/translations_helpers/it'
@@ -1,12 +0,0 @@
1
- module NumbersAndWords
2
- module TranslationsHelpers
3
- module En
4
- include NumbersAndWords::TranslationsHelpers::Base
5
- include NumbersAndWords::TranslationsHelpers::Families::Latin
6
-
7
- def translation_tens_with_ones numbers
8
- super numbers, '-'
9
- end
10
- end
11
- end
12
- end
@@ -1,30 +0,0 @@
1
- module NumbersAndWords
2
- module TranslationsHelpers
3
- module Families
4
- module Base
5
-
6
- private
7
-
8
- def translation_teens number
9
- t(:teens)[number]
10
- end
11
-
12
- def translation_tens number
13
- t(:tens)[number]
14
- end
15
-
16
- def translation_tens_with_ones numbers, separator = ' '
17
- [translation_tens(numbers[1]), translation_ones(numbers[0])].join separator
18
- end
19
-
20
- def translation_megs capacity, number = nil
21
- number ? t(translation_mega(capacity), :count => number) : t(:mega)[capacity]
22
- end
23
-
24
- def translation_mega capacity
25
- t(:mega)[capacity]
26
- end
27
- end
28
- end
29
- end
30
- end
@@ -1,28 +0,0 @@
1
- module NumbersAndWords
2
- module TranslationsHelpers
3
- module Families
4
- module Cyrillic
5
- include NumbersAndWords::TranslationsHelpers::Families::Base
6
-
7
- private
8
-
9
- def translation_ones number
10
- gender = figures.is_a_thousand_capacity?(current_capacity) ? :female : :male
11
- t([:ones, gender].join('_'))[number]
12
- end
13
-
14
- def translation_hundreds number
15
- t(:hundreds)[number]
16
- end
17
-
18
- def translation_megs capacity
19
- super(capacity, figures.number_in_capacity(capacity))
20
- end
21
-
22
- def zero
23
- t(:ones_male)[0]
24
- end
25
- end
26
- end
27
- end
28
- end
@@ -1,23 +0,0 @@
1
- module NumbersAndWords
2
- module TranslationsHelpers
3
- module Families
4
- module Latin
5
- include NumbersAndWords::TranslationsHelpers::Families::Base
6
-
7
- private
8
-
9
- def translation_ones number
10
- t(:ones)[number]
11
- end
12
-
13
- def translation_hundreds number
14
- [t(:ones)[number], t(:hundreds)].join ' '
15
- end
16
-
17
- def zero
18
- t(:ones)[0]
19
- end
20
- end
21
- end
22
- end
23
- end
@@ -1,34 +0,0 @@
1
- module NumbersAndWords
2
- module TranslationsHelpers
3
- module Fr
4
- include NumbersAndWords::TranslationsHelpers::Base
5
- include NumbersAndWords::TranslationsHelpers::Families::Latin
6
-
7
- SPECIAL_TENS_CASE = 8
8
-
9
- private
10
-
11
- def translation_tens number, alone = true
12
- (SPECIAL_TENS_CASE == number and alone) ? t(:eighty) : super(number)
13
- end
14
-
15
- def translation_tens_with_ones numbers
16
- if [7, 9].include? numbers[1]
17
- [translation_tens(numbers[1] - 1, false), translation_teens(numbers[0])].join '-'
18
- else
19
- union = numbers[0] == 1 ? ' et ' : '-'
20
- [translation_tens(numbers[1], false), translation_ones(numbers[0])].join union
21
- end
22
- end
23
-
24
- def translation_hundreds number, pluralize = false
25
- hundreds = t(:hundreds, :count => pluralize ? number : 1)
26
- (number == 1) ? hundreds : [t(:ones)[number], hundreds].join(' ')
27
- end
28
-
29
- def translation_megs capacity
30
- super(capacity, figures.number_in_capacity(capacity))
31
- end
32
- end
33
- end
34
- end
@@ -1,16 +0,0 @@
1
- module NumbersAndWords
2
- module TranslationsHelpers
3
- module It
4
- include NumbersAndWords::TranslationsHelpers::Base
5
- include NumbersAndWords::TranslationsHelpers::Families::Latin
6
-
7
- def translation_tens_with_ones numbers
8
- super numbers, ''
9
- end
10
-
11
- def translation_hundreds number
12
- [[number], t(:hundreds)].join ' '
13
- end
14
- end
15
- end
16
- end
@@ -1,18 +0,0 @@
1
- module NumbersAndWords
2
- module TranslationsHelpers
3
- module Nl
4
- include NumbersAndWords::TranslationsHelpers::Base
5
- include NumbersAndWords::TranslationsHelpers::Families::Latin
6
-
7
- private
8
-
9
- def translation_tens_with_ones numbers
10
- [translation_ones(numbers[0]), translation_tens(numbers[1])].join 'en'
11
- end
12
-
13
- def translation_hundreds number
14
- 1 == number ? t(:hundreds) : [t(:ones)[number], t(:hundreds)].join
15
- end
16
- end
17
- end
18
- end
@@ -1,8 +0,0 @@
1
- module NumbersAndWords
2
- module TranslationsHelpers
3
- module Ru
4
- include NumbersAndWords::TranslationsHelpers::Base
5
- include NumbersAndWords::TranslationsHelpers::Families::Cyrillic
6
- end
7
- end
8
- end
@@ -1,8 +0,0 @@
1
- module NumbersAndWords
2
- module TranslationsHelpers
3
- module Tr
4
- include NumbersAndWords::TranslationsHelpers::Base
5
- include NumbersAndWords::TranslationsHelpers::Families::Latin
6
- end
7
- end
8
- end
@@ -1,8 +0,0 @@
1
- module NumbersAndWords
2
- module TranslationsHelpers
3
- module Ua
4
- include NumbersAndWords::TranslationsHelpers::Base
5
- include NumbersAndWords::TranslationsHelpers::Families::Cyrillic
6
- end
7
- end
8
- end