numbers_and_words 0.5.0 → 0.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
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 @@
1
+ require 'numbers_and_words/strategies/figures_converter/options/ru/gender'
@@ -0,0 +1,28 @@
1
+ module NumbersAndWords
2
+ module Strategies
3
+ module FiguresConverter
4
+ module Options
5
+ module Ru
6
+ class Gender
7
+ attr_accessor :strategy, :options
8
+
9
+ def initialize proxy, *args, &block
10
+ @strategy = proxy.strategy
11
+ @options = proxy.options
12
+ end
13
+
14
+ def result
15
+ active? ? @options[:gender].to_sym : :male
16
+ end
17
+
18
+ private
19
+
20
+ def active?
21
+ @options[:gender]
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1 @@
1
+ require 'numbers_and_words/strategies/figures_converter/options/ua/gender'
@@ -0,0 +1,28 @@
1
+ module NumbersAndWords
2
+ module Strategies
3
+ module FiguresConverter
4
+ module Options
5
+ module Ua
6
+ class Gender
7
+ attr_accessor :strategy, :options
8
+
9
+ def initialize proxy, *args, &block
10
+ @strategy = proxy.strategy
11
+ @options = proxy.options
12
+ end
13
+
14
+ def result
15
+ active? ? @options[:gender].to_sym : :male
16
+ end
17
+
18
+ private
19
+
20
+ def active?
21
+ @options[:gender]
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,25 @@
1
+ require 'numbers_and_words/translations/base'
2
+ require 'numbers_and_words/translations/families/base'
3
+ require 'numbers_and_words/translations/families/cyrillic'
4
+ require 'numbers_and_words/translations/families/latin'
5
+ require 'numbers_and_words/translations/extensions/fraction_significance'
6
+ require 'numbers_and_words/translations/ru'
7
+ require 'numbers_and_words/translations/en'
8
+ require 'numbers_and_words/translations/ua'
9
+ require 'numbers_and_words/translations/tr'
10
+ require 'numbers_and_words/translations/fr'
11
+ require 'numbers_and_words/translations/nl'
12
+ require 'numbers_and_words/translations/it'
13
+ require 'numbers_and_words/translations/hu'
14
+ require 'numbers_and_words/translations/se'
15
+ require 'numbers_and_words/translations/es'
16
+
17
+ module NumbersAndWords
18
+ module Translations
19
+ class << self
20
+ def factory
21
+ "NumbersAndWords::Translations::#{::I18n.locale.to_s.titleize}".constantize.new
22
+ end
23
+ end
24
+ end
25
+ end
@@ -1,6 +1,6 @@
1
1
  module NumbersAndWords
2
- module TranslationsHelpers
3
- module Base
2
+ module Translations
3
+ class Base
4
4
  I18N_NAMESPACE = :numbers
5
5
 
6
6
  def t attribute, options = {}
@@ -0,0 +1,8 @@
1
+ module NumbersAndWords
2
+ module Translations
3
+ class En < Base
4
+ include NumbersAndWords::Translations::Families::Latin
5
+ include NumbersAndWords::Translations::Extensions::FractionSignificance
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,37 @@
1
+ module NumbersAndWords
2
+ module Translations
3
+ class Es < Base
4
+ include NumbersAndWords::Translations::Families::Latin
5
+
6
+ TENS_CASE = 2
7
+
8
+ def one options = {}
9
+ t(:one)
10
+ end
11
+
12
+ def ones number, options = {}
13
+ t(:ones)[number]
14
+ end
15
+
16
+ def tens numbers, options = {}
17
+ options[:alone] = true if options[:alone].nil?
18
+ (numbers == TENS_CASE && options[:alone]) ? t(:twenty) : super(numbers)
19
+ end
20
+
21
+ def tens_with_ones numbers, options = {}
22
+ inter = numbers[1] == TENS_CASE ? "" : " y "
23
+ [tens(numbers[1], :alone => false), ones(numbers[0])].join inter
24
+ end
25
+
26
+ def hundreds number, options = {}
27
+ options[:is_hundred] = false if options[:is_hundred].nil?
28
+ options[:is_hundred] ? t(:one_hundred) : t(:hundreds)[number - 1]
29
+ end
30
+
31
+ def megs capacity, options = {}
32
+ options[:is_one] = false if options[:is_one].nil?
33
+ options[:is_one] ? t(:mega)[capacity] : t(:megas)[capacity]
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,25 @@
1
+ module NumbersAndWords
2
+ module Translations
3
+ module Extensions
4
+ module FractionSignificance
5
+
6
+ def micros capacity, number = nil, separator = '-'
7
+ micro, prefix = capacity
8
+ micros = number ? t(micro(micro), :count => number) : micro(micro)
9
+ [micro_prefix(prefix), micros].compact.join separator
10
+ end
11
+
12
+ def micro capacity
13
+ t(:micro)[capacity]
14
+ end
15
+
16
+ def micro_prefix capacity
17
+ case capacity
18
+ when 2 then t(:hundreds)
19
+ when 1 then tens(1)
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,33 @@
1
+ module NumbersAndWords
2
+ module Translations
3
+ module Families
4
+ module Base
5
+
6
+ def teens numbers, options = {}
7
+ t("#{options[:prefix]}.teens")[numbers[0]]
8
+ end
9
+
10
+ def tens number, options = {}
11
+ t("#{options[:prefix]}.tens")[number]
12
+ end
13
+
14
+ def tens_with_ones numbers, options = {}
15
+ [tens(numbers[1]), ones(numbers[0], options)].join options[:separator]
16
+ end
17
+
18
+ def megs capacity, options = {}
19
+ number, mega_name = options[:number], "#{options[:prefix]}.mega"
20
+ number ? t(mega(capacity), :count => number) : t(mega_name)[capacity]
21
+ end
22
+
23
+ def mega capacity
24
+ t(:mega)[capacity]
25
+ end
26
+
27
+ def union
28
+ t :union
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,29 @@
1
+ module NumbersAndWords
2
+ module Translations
3
+ module Families
4
+ module Cyrillic
5
+ include NumbersAndWords::Translations::Families::Base
6
+
7
+ def ones number, options = {}
8
+ t(:ones)[options[:gender]][number]
9
+ end
10
+
11
+ def tens_with_ones numbers, options = {}
12
+ [tens(numbers[1]), ones(numbers[0], options)].join ' '
13
+ end
14
+
15
+ def hundreds number, options = {}
16
+ t(:hundreds)[number]
17
+ end
18
+
19
+ def zero options = {}
20
+ t(:ones).values.first[0]
21
+ end
22
+
23
+ def integral number, options = {}
24
+ t(:integral, :count => number)
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,23 @@
1
+ module NumbersAndWords
2
+ module Translations
3
+ module Families
4
+ module Latin
5
+ include NumbersAndWords::Translations::Families::Base
6
+
7
+ #private
8
+
9
+ def ones number, options = {}
10
+ t([options[:prefix], :ones].join('.'))[number]
11
+ end
12
+
13
+ def hundreds number, options = {}
14
+ [t(:ones)[number], t([options[:prefix], :hundreds].join('.'))].join options[:separator] || ' '
15
+ end
16
+
17
+ def zero options = {}
18
+ t([options[:prefix], :ones].join('.'))[0]
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,29 @@
1
+ module NumbersAndWords
2
+ module Translations
3
+ class Fr < Base
4
+ include NumbersAndWords::Translations::Families::Latin
5
+
6
+ SPECIAL_TENS_CASE = 8
7
+
8
+ def tens number, options = {}
9
+ options[:alone] = true if options[:alone].nil?
10
+ (SPECIAL_TENS_CASE == number and options[:alone]) ? t(:eighty) : super(number)
11
+ end
12
+
13
+ def tens_with_ones numbers, options = {}
14
+ if [7, 9].include? numbers[1]
15
+ [tens(numbers[1] - 1, :alone => false), teens(numbers)].join '-'
16
+ else
17
+ union = numbers[0] == 1 ? ' et ' : '-'
18
+ [tens(numbers[1], :alone => false), ones(numbers[0])].join union
19
+ end
20
+ end
21
+
22
+ def hundreds number, options = {}
23
+ options[:pluralize] = false if options[:pluralize].nil?
24
+ hundreds = t(:hundreds, :count => options[:pluralize] ? number : 1)
25
+ (number == 1) ? hundreds : [t(:ones)[number], hundreds].join(' ')
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,26 @@
1
+ module NumbersAndWords
2
+ module Translations
3
+ class Hu < Base
4
+ include NumbersAndWords::Translations::Families::Latin
5
+ include NumbersAndWords::Translations::Extensions::FractionSignificance
6
+
7
+ def tens_with_ones numbers, options = {}
8
+ ones, tens = numbers
9
+ [t(:tens_with_ones)[tens], t([options[:prefix], :ones_with_tens].join('.'))[ones]].join ''
10
+ end
11
+
12
+ def hundreds number, options = {}
13
+ options[:separator] = ''
14
+ super number, options
15
+ end
16
+
17
+ def micros capacity, number = nil, separator = ''
18
+ super capacity, nil, separator
19
+ end
20
+
21
+ def union
22
+ t :union
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,15 @@
1
+ module NumbersAndWords
2
+ module Translations
3
+ class It < Base
4
+ include NumbersAndWords::Translations::Families::Latin
5
+
6
+ def tens_with_ones numbers, options = {}
7
+ super numbers, :separator => ''
8
+ end
9
+
10
+ def hundreds number, options = {}
11
+ [[number], t(:hundreds)].join ' '
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,15 @@
1
+ module NumbersAndWords
2
+ module Translations
3
+ class Nl < Base
4
+ include NumbersAndWords::Translations::Families::Latin
5
+
6
+ def tens_with_ones numbers, options = {}
7
+ [ones(numbers[0]), tens(numbers[1])].join 'en'
8
+ end
9
+
10
+ def hundreds number, options = {}
11
+ 1 == number ? t(:hundreds) : [t(:ones)[number], t(:hundreds)].join
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,25 @@
1
+ module NumbersAndWords
2
+ module Translations
3
+ class Ru < Base
4
+ include NumbersAndWords::Translations::Families::Cyrillic
5
+ include NumbersAndWords::Translations::Extensions::FractionSignificance
6
+
7
+ def micros capacity, number = nil, separator = ' '
8
+ micro, prefix = capacity
9
+ micros = t(:micro, :count => number)[micro]
10
+ [micro_prefix(prefix), micros].compact.join separator
11
+ end
12
+
13
+ def micro_prefix capacity
14
+ case capacity
15
+ when 2 then t(:sub_micro)[2]
16
+ when 1 then t(:sub_micro)[1]
17
+ end
18
+ end
19
+
20
+ #def fraction_separator options = {}
21
+ # super if options[:with_fractional_separator]
22
+ #end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,11 @@
1
+ module NumbersAndWords
2
+ module Translations
3
+ class Se < Base
4
+ include NumbersAndWords::Translations::Families::Latin
5
+
6
+ def tens_with_ones numbers, options = {}
7
+ super numbers, :separator => '-'
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,11 @@
1
+ module NumbersAndWords
2
+ module Translations
3
+ class Tr < Base
4
+ include NumbersAndWords::Translations::Families::Latin
5
+
6
+ def tens_with_ones numbers, options = {}
7
+ super numbers, :separator => ' '
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,21 @@
1
+ module NumbersAndWords
2
+ module Translations
3
+ class Ua < Base
4
+ include NumbersAndWords::Translations::Families::Cyrillic
5
+ include NumbersAndWords::Translations::Extensions::FractionSignificance
6
+
7
+ def micros capacity, number = nil, separator = ' '
8
+ micro, prefix = capacity
9
+ micros = t(:micro, :count => number)[micro]
10
+ [micro_prefix(prefix), micros].compact.join separator
11
+ end
12
+
13
+ def micro_prefix capacity
14
+ case capacity
15
+ when 2 then t(:sub_micro)[2]
16
+ when 1 then t(:sub_micro)[1]
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
@@ -1,3 +1,3 @@
1
1
  module NumbersAndWords
2
- VERSION = '0.5.0'
2
+ VERSION = '0.6.0'
3
3
  end