numbers_and_words 0.11.2 → 0.11.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (74) hide show
  1. checksums.yaml +4 -4
  2. data/README.rdoc +10 -0
  3. data/lib/numbers_and_words/i18n/locales/numbers.cs.yml +37 -26
  4. data/lib/numbers_and_words/i18n/locales/numbers.de.yml +5 -4
  5. data/lib/numbers_and_words/i18n/locales/numbers.en-GB.yml +24 -8
  6. data/lib/numbers_and_words/i18n/locales/numbers.en.yml +10 -6
  7. data/lib/numbers_and_words/i18n/locales/numbers.es.yml +6 -5
  8. data/lib/numbers_and_words/i18n/locales/numbers.et.yml +4 -4
  9. data/lib/numbers_and_words/i18n/locales/numbers.fr.yml +45 -41
  10. data/lib/numbers_and_words/i18n/locales/numbers.hu.yml +11 -7
  11. data/lib/numbers_and_words/i18n/locales/numbers.it.yml +3 -3
  12. data/lib/numbers_and_words/i18n/locales/numbers.ka.yml +6 -14
  13. data/lib/numbers_and_words/i18n/locales/numbers.lt.yml +4 -5
  14. data/lib/numbers_and_words/i18n/locales/numbers.lv.yml +4 -5
  15. data/lib/numbers_and_words/i18n/locales/numbers.nl.yml +4 -3
  16. data/lib/numbers_and_words/i18n/locales/numbers.pt-BR.yml +51 -22
  17. data/lib/numbers_and_words/i18n/locales/numbers.pt.yml +21 -8
  18. data/lib/numbers_and_words/i18n/locales/numbers.ru.yml +39 -27
  19. data/lib/numbers_and_words/i18n/locales/numbers.se.yml +3 -3
  20. data/lib/numbers_and_words/i18n/locales/numbers.tr.yml +3 -3
  21. data/lib/numbers_and_words/i18n/locales/numbers.ua.yml +39 -15
  22. data/lib/numbers_and_words/i18n/locales/numbers.vi.yml +13 -0
  23. data/lib/numbers_and_words/strategies/array_joiner/languages.rb +1 -0
  24. data/lib/numbers_and_words/strategies/array_joiner/languages/en-GB.rb +1 -1
  25. data/lib/numbers_and_words/strategies/array_joiner/languages/families/base.rb +3 -3
  26. data/lib/numbers_and_words/strategies/array_joiner/languages/vi.rb +10 -0
  27. data/lib/numbers_and_words/strategies/figures_converter/decorators.rb +1 -0
  28. data/lib/numbers_and_words/strategies/figures_converter/decorators/hu/fractional.rb +1 -1
  29. data/lib/numbers_and_words/strategies/figures_converter/decorators/vi.rb +3 -0
  30. data/lib/numbers_and_words/strategies/figures_converter/{languages/families/latin.rb → decorators/vi/base.rb} +3 -4
  31. data/lib/numbers_and_words/strategies/figures_converter/decorators/vi/fractional.rb +12 -0
  32. data/lib/numbers_and_words/strategies/figures_converter/decorators/vi/integral.rb +12 -0
  33. data/lib/numbers_and_words/strategies/figures_converter/languages.rb +11 -15
  34. data/lib/numbers_and_words/strategies/figures_converter/languages/base.rb +2 -2
  35. data/lib/numbers_and_words/strategies/figures_converter/languages/cs.rb +2 -4
  36. data/lib/numbers_and_words/strategies/figures_converter/languages/de.rb +5 -7
  37. data/lib/numbers_and_words/strategies/figures_converter/languages/en.rb +0 -2
  38. data/lib/numbers_and_words/strategies/figures_converter/languages/es.rb +0 -2
  39. data/lib/numbers_and_words/strategies/figures_converter/languages/et.rb +0 -2
  40. data/lib/numbers_and_words/strategies/figures_converter/languages/fr.rb +10 -12
  41. data/lib/numbers_and_words/strategies/figures_converter/languages/hu.rb +0 -2
  42. data/lib/numbers_and_words/strategies/figures_converter/languages/it.rb +0 -1
  43. data/lib/numbers_and_words/strategies/figures_converter/languages/ka.rb +10 -12
  44. data/lib/numbers_and_words/strategies/figures_converter/languages/lt.rb +6 -12
  45. data/lib/numbers_and_words/strategies/figures_converter/languages/lv.rb +2 -14
  46. data/lib/numbers_and_words/strategies/figures_converter/languages/nl.rb +0 -2
  47. data/lib/numbers_and_words/strategies/figures_converter/languages/pt-BR.rb +1 -3
  48. data/lib/numbers_and_words/strategies/figures_converter/languages/pt.rb +1 -3
  49. data/lib/numbers_and_words/strategies/figures_converter/languages/se.rb +0 -1
  50. data/lib/numbers_and_words/strategies/figures_converter/languages/tr.rb +2 -4
  51. data/lib/numbers_and_words/strategies/figures_converter/languages/vi.rb +96 -0
  52. data/lib/numbers_and_words/translations.rb +1 -0
  53. data/lib/numbers_and_words/translations/cs.rb +4 -31
  54. data/lib/numbers_and_words/translations/de.rb +3 -3
  55. data/lib/numbers_and_words/translations/en-GB.rb +3 -1
  56. data/lib/numbers_and_words/translations/es.rb +5 -20
  57. data/lib/numbers_and_words/translations/et.rb +2 -7
  58. data/lib/numbers_and_words/translations/extensions/fraction_significance.rb +4 -4
  59. data/lib/numbers_and_words/translations/families/base.rb +3 -3
  60. data/lib/numbers_and_words/translations/families/cyrillic.rb +4 -8
  61. data/lib/numbers_and_words/translations/fr.rb +9 -14
  62. data/lib/numbers_and_words/translations/hu.rb +2 -7
  63. data/lib/numbers_and_words/translations/ka.rb +3 -13
  64. data/lib/numbers_and_words/translations/lt.rb +2 -11
  65. data/lib/numbers_and_words/translations/lv.rb +2 -11
  66. data/lib/numbers_and_words/translations/nl.rb +3 -2
  67. data/lib/numbers_and_words/translations/pt-BR.rb +14 -21
  68. data/lib/numbers_and_words/translations/pt.rb +3 -12
  69. data/lib/numbers_and_words/translations/ru.rb +0 -17
  70. data/lib/numbers_and_words/translations/tr.rb +0 -4
  71. data/lib/numbers_and_words/translations/ua.rb +0 -13
  72. data/lib/numbers_and_words/translations/vi.rb +21 -0
  73. data/lib/numbers_and_words/version.rb +1 -1
  74. metadata +11 -4
@@ -22,6 +22,7 @@ require 'numbers_and_words/translations/pt'
22
22
  require 'numbers_and_words/translations/pt-BR'
23
23
  require 'numbers_and_words/translations/ka'
24
24
  require 'numbers_and_words/translations/cs'
25
+ require 'numbers_and_words/translations/vi'
25
26
 
26
27
  module NumbersAndWords
27
28
  module Translations
@@ -12,53 +12,26 @@ module NumbersAndWords
12
12
  t([options[:prefix], :ones, options[:gender]].join('.'))[number]
13
13
  end
14
14
 
15
- # for 20, 30, 60
16
15
  def tens(number, options = {})
17
16
  t([options[:prefix], :tens, gender_to_use(options)].join('.'))[number]
18
17
  end
19
18
 
20
- # for 12, 13, 19
21
- def teens(number_arr, options = {})
22
- t([options[:prefix], :teens, gender_to_use(options)].join('.'))[number_arr.first]
19
+ def teens(numbers, options = {})
20
+ t([options[:prefix], :teens, gender_to_use(options)].join('.'))[numbers[0]]
23
21
  end
24
22
 
25
- # for 42, 23, 69
26
- def tens_with_ones(numbers_arr, options = {})
27
- connector = ' '
28
- [tens(numbers_arr[1], options), connector, ones(numbers_arr[0], options)].join
23
+ def tens_with_ones(numbers, options = {})
24
+ [tens(numbers[1], options), ones(numbers[0], options)].join(' ')
29
25
  end
30
26
 
31
27
  def hundreds(number, options = {})
32
28
  t([options[:prefix], :hundreds, gender_to_use(options)].join('.'))[number]
33
29
  end
34
30
 
35
- def megs(capacity, options = {})
36
- number = options[:number]
37
- mega_name = "#{options[:prefix]}.mega"
38
- number ? t(mega(capacity), count: number) : t(mega_name)[capacity]
39
- end
40
-
41
- def mega(capacity)
42
- t(:mega)[capacity]
43
- end
44
-
45
31
  def integral(number, _options = {})
46
32
  t(:integral, count: number)
47
33
  end
48
34
 
49
- def micros(capacity, number = nil, separator = '')
50
- micro, prefix = capacity
51
- micros = t(:micro, count: number)[micro]
52
- [micro_prefix(prefix), micros].compact.join separator
53
- end
54
-
55
- def micro_prefix(capacity)
56
- case capacity
57
- when 2 then t(:sub_micro)[2]
58
- when 1 then t(:sub_micro)[1]
59
- end
60
- end
61
-
62
35
  private
63
36
 
64
37
  def ordinal?(options)
@@ -1,7 +1,7 @@
1
1
  module NumbersAndWords
2
2
  module Translations
3
3
  class De < Base
4
- include NumbersAndWords::Translations::Families::Latin
4
+ include NumbersAndWords::Translations::Families::Base
5
5
  DEFAULT_POSTFIX = :combine
6
6
 
7
7
  def ones(number, options = {})
@@ -9,11 +9,11 @@ module NumbersAndWords
9
9
  end
10
10
 
11
11
  def tens_with_ones(numbers, options = {})
12
- [tens(numbers[1]), ones(numbers[0], options)].reverse.join 'und'
12
+ [tens(numbers[1]), ones(numbers[0], options)].reverse.join(union)
13
13
  end
14
14
 
15
15
  def hundreds(number, _options = {})
16
- [ones(number), t(:hundreds)].join('')
16
+ [ones(number), t(:hundreds)].join
17
17
  end
18
18
 
19
19
  def zero(_options = {})
@@ -1,6 +1,8 @@
1
1
  module NumbersAndWords
2
2
  module Translations
3
- class EnGb < En
3
+ class EnGb < Base
4
+ include NumbersAndWords::Translations::Families::Latin
5
+ include NumbersAndWords::Translations::Extensions::FractionSignificance
4
6
  end
5
7
  end
6
8
  end
@@ -1,7 +1,7 @@
1
1
  module NumbersAndWords
2
2
  module Translations
3
3
  class Es < Base
4
- include NumbersAndWords::Translations::Families::Latin
4
+ include NumbersAndWords::Translations::Families::Base
5
5
  include NumbersAndWords::Translations::Extensions::FractionSignificance
6
6
 
7
7
  def zero(_options = {})
@@ -15,34 +15,19 @@ module NumbersAndWords
15
15
  t([:ones, options[:gender]].join('.'))[number]
16
16
  end
17
17
 
18
+ def tens_with_ones(numbers, options = {})
19
+ super numbers, options.merge(separator: " #{union} ")
20
+ end
21
+
18
22
  def twenties_with_ones(numbers, options = {})
19
23
  return t(%i[twenties apocopated].join('.')) if options[:is_apocopated]
20
24
  t([:twenties, options[:gender]].join('.'))[numbers[0]]
21
25
  end
22
26
 
23
- def tens_with_ones(numbers, options = {})
24
- [tens(numbers[1], alone: false),
25
- t(:union),
26
- ones(numbers[0], options)].join(' ')
27
- end
28
-
29
27
  def hundreds(number, options = {})
30
28
  return t(%i[hundreds apocopated].join('.')) if options[:is_apocopated]
31
29
  t([:hundreds, options[:gender]].join('.'))[number]
32
30
  end
33
-
34
- def micros(capacity, number = nil)
35
- micro, prefix = capacity
36
- micros = number ? t(micro(micro), count: number) : micro(micro)
37
- [micro_prefix(prefix), micros].compact.join
38
- end
39
-
40
- def micro_prefix(capacity)
41
- case capacity
42
- when 2 then t('micro_prefix.hundreds')
43
- when 1 then t('micro_prefix.tens')
44
- end
45
- end
46
31
  end
47
32
  end
48
33
  end
@@ -3,13 +3,8 @@ module NumbersAndWords
3
3
  class Et < Base
4
4
  include NumbersAndWords::Translations::Families::Latin
5
5
 
6
- def tens_with_ones(numbers, _options = {})
7
- [tens(numbers[1], alone: false), ones(numbers[0])].join ' '
8
- end
9
-
10
- def hundreds(number, options = {})
11
- options[:separator] = ''
12
- super number, options
6
+ def hundreds(number, _options = {})
7
+ super number, separator: ''
13
8
  end
14
9
  end
15
10
  end
@@ -2,10 +2,10 @@ module NumbersAndWords
2
2
  module Translations
3
3
  module Extensions
4
4
  module FractionSignificance
5
- def micros(capacity, number = nil, separator = '-')
5
+ def micros(capacity, number = nil)
6
6
  micro, prefix = capacity
7
7
  micros = number ? t(micro(micro), count: number) : micro(micro)
8
- [micro_prefix(prefix), micros].compact.join separator
8
+ [micro_prefix(prefix), micros].compact.join(t('micro_prefix.union'))
9
9
  end
10
10
 
11
11
  def micro(capacity)
@@ -14,8 +14,8 @@ module NumbersAndWords
14
14
 
15
15
  def micro_prefix(capacity)
16
16
  case capacity
17
- when 2 then t(:hundreds)
18
- when 1 then tens(1)
17
+ when 2 then t('micro_prefix.hundreds')
18
+ when 1 then t('micro_prefix.tens')
19
19
  end
20
20
  end
21
21
  end
@@ -11,7 +11,7 @@ module NumbersAndWords
11
11
  end
12
12
 
13
13
  def tens_with_ones(numbers, options = {})
14
- [tens(numbers[1]), ones(numbers[0], options)].join options[:separator]
14
+ [tens(numbers[1]), ones(numbers[0], options)].join options[:separator] || ' '
15
15
  end
16
16
 
17
17
  def megs(capacity, options = {})
@@ -28,8 +28,8 @@ module NumbersAndWords
28
28
  t :union
29
29
  end
30
30
 
31
- def union_separator
32
- t :union_separator
31
+ def micro_separator
32
+ t :micro_separator
33
33
  end
34
34
  end
35
35
  end
@@ -4,22 +4,18 @@ module NumbersAndWords
4
4
  module Cyrillic
5
5
  include NumbersAndWords::Translations::Families::Base
6
6
 
7
- def ones(number, options = {})
8
- t(:ones)[options[:gender]][number]
7
+ def zero(_options = {})
8
+ t(:ones).values.first[0]
9
9
  end
10
10
 
11
- def tens_with_ones(numbers, options = {})
12
- [tens(numbers[1]), ones(numbers[0], options)].join ' '
11
+ def ones(number, options = {})
12
+ t(:ones)[options[:gender]][number]
13
13
  end
14
14
 
15
15
  def hundreds(number, _options = {})
16
16
  t(:hundreds)[number]
17
17
  end
18
18
 
19
- def zero(_options = {})
20
- t(:ones).values.first[0]
21
- end
22
-
23
19
  def integral(number, _options = {})
24
20
  t(:integral, count: number)
25
21
  end
@@ -7,30 +7,25 @@ module NumbersAndWords
7
7
  SPECIAL_TENS_CASE = 8
8
8
 
9
9
  def tens(number, options = {})
10
- options[:alone] = true if options[:alone].nil?
11
- SPECIAL_TENS_CASE == number && options[:alone] ? t(:eighty) : super(number)
10
+ return t(:eighty) if number == SPECIAL_TENS_CASE && options[:alone].nil?
11
+ super number, options
12
12
  end
13
13
 
14
14
  def tens_with_ones(numbers, _options = {})
15
15
  if [7, 9].include? numbers[1]
16
- [tens(numbers[1] - 1, alone: false), teens(numbers)].join '-'
16
+ [tens(numbers[1] - 1, alone: false), teens(numbers)].join('-')
17
17
  else
18
- union = numbers[0] == 1 ? ' et ' : '-'
19
- [tens(numbers[1], alone: false), ones(numbers[0])].join union
18
+ separator = numbers[0] == 1 ? " #{union} " : '-'
19
+ [tens(numbers[1], alone: false), ones(numbers[0])].join(separator)
20
20
  end
21
21
  end
22
22
 
23
23
  def hundreds(number, options = {})
24
- options[:pluralize] = false if options[:pluralize].nil?
25
- hundreds = t(:hundreds, count: options[:pluralize] ? number : 1)
26
- number == 1 ? hundreds : [t(:ones)[number], hundreds].join(' ')
27
- end
24
+ count = options[:pluralize] ? number : 1
25
+ hundreds = t(:hundreds, count: count)
28
26
 
29
- def micro_prefix(capacity)
30
- case capacity
31
- when 2 then t(:hundreds, count: 1)
32
- when 1 then tens(1)
33
- end
27
+ return hundreds if number == 1
28
+ [t(:ones)[number], hundreds].join(' ')
34
29
  end
35
30
  end
36
31
  end
@@ -6,16 +6,11 @@ module NumbersAndWords
6
6
 
7
7
  def tens_with_ones(numbers, options = {})
8
8
  ones, tens = numbers
9
- [t(:tens_with_ones)[tens], t([options[:prefix], :ones_with_tens].join('.'))[ones]].join ''
9
+ [t(:tens_with_ones)[tens], t([options[:prefix], :ones_with_tens].join('.'))[ones]].join
10
10
  end
11
11
 
12
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
13
+ super number, options.merge(separator: '')
19
14
  end
20
15
  end
21
16
  end
@@ -46,26 +46,16 @@ module NumbersAndWords
46
46
  ones(numbers[0])
47
47
  end
48
48
 
49
- [t([:partials, range[:name]].join('.')), minor].join ''
49
+ [t([:partials, range[:name]].join('.')), minor].join
50
50
  end
51
51
 
52
52
  def hundreds(number, options = {})
53
53
  options[:prefix] ||= options[:only_hundreds] == true ? nil : :partials
54
54
 
55
- parts = [t([options[:prefix], :one_hundred].join('.'))]
55
+ parts = [t([options[:prefix], :hundreds].join('.'))]
56
56
  parts.unshift(ones(number, prefix: :partials)) if number > 1
57
57
 
58
- parts.join ''
59
- end
60
-
61
- def megs(capacity, options = {})
62
- if capacity == 1
63
- t([options[:prefix], :one_thousand].join('.'))
64
- elsif capacity == 2
65
- t([options[:prefix], :one_million].join('.'))
66
- elsif capacity == 3
67
- t([options[:prefix], :one_billion].join('.'))
68
- end
58
+ parts.join
69
59
  end
70
60
  end
71
61
  end
@@ -3,17 +3,8 @@ module NumbersAndWords
3
3
  class Lt < Base
4
4
  include NumbersAndWords::Translations::Families::Latin
5
5
 
6
- def tens(number, _options = {})
7
- super(number)
8
- end
9
-
10
- def tens_with_ones(numbers, _options = {})
11
- [tens(numbers[1], alone: false), ones(numbers[0])].join ' '
12
- end
13
-
14
- def hundreds(number, options = {})
15
- options[:is_hundred] = false if options[:is_hundred].nil?
16
- options[:is_hundred] ? t(:one_hundred) : t(:hundreds)[number - 1]
6
+ def hundreds(number, _options = {})
7
+ t(:hundreds)[number]
17
8
  end
18
9
  end
19
10
  end
@@ -3,17 +3,8 @@ module NumbersAndWords
3
3
  class Lv < Base
4
4
  include NumbersAndWords::Translations::Families::Latin
5
5
 
6
- def tens(number, _options = {})
7
- super(number)
8
- end
9
-
10
- def tens_with_ones(numbers, _options = {})
11
- [tens(numbers[1], alone: false), ones(numbers[0])].join ' '
12
- end
13
-
14
- def hundreds(number, options = {})
15
- options[:is_hundred] = false if options[:is_hundred].nil?
16
- options[:is_hundred] ? t(:one_hundred) : t(:hundreds)[number - 1]
6
+ def hundreds(number, _options = {})
7
+ t(:hundreds)[number]
17
8
  end
18
9
  end
19
10
  end
@@ -4,11 +4,12 @@ module NumbersAndWords
4
4
  include NumbersAndWords::Translations::Families::Latin
5
5
 
6
6
  def tens_with_ones(numbers, _options = {})
7
- [ones(numbers[0]), tens(numbers[1])].join 'en'
7
+ [ones(numbers[0]), tens(numbers[1])].join(union)
8
8
  end
9
9
 
10
10
  def hundreds(number, _options = {})
11
- number == 1 ? t(:hundreds) : [t(:ones)[number], t(:hundreds)].join
11
+ return t(:hundreds) if number == 1
12
+ super number, separator: ''
12
13
  end
13
14
  end
14
15
  end
@@ -1,7 +1,7 @@
1
1
  module NumbersAndWords
2
2
  module Translations
3
3
  class PtBr < Base
4
- include NumbersAndWords::Translations::Families::Latin
4
+ include NumbersAndWords::Translations::Families::Base
5
5
  include NumbersAndWords::Translations::Extensions::FractionSignificance
6
6
 
7
7
  def integral(number, _options = {})
@@ -18,11 +18,9 @@ module NumbersAndWords
18
18
  end
19
19
 
20
20
  def tens(number, options = {})
21
- options[:alone] = true if options[:alone].nil?
22
21
  path = [options[:prefix], :tens]
23
- path.push(options[:gender]) if ordinal? options
24
- translated = t(path.join('.'))[number]
25
- options[:alone] ? translated : "#{union} " + translated
22
+ path.push(options[:gender]) if ordinal?(options)
23
+ t(path.join('.'))[number]
26
24
  end
27
25
 
28
26
  def teens(number, options = {})
@@ -31,33 +29,28 @@ module NumbersAndWords
31
29
  end
32
30
 
33
31
  def tens_with_ones(numbers, options = {})
34
- connector = ' '
35
- connector = " #{union} " unless ordinal? options
32
+ connector = ordinal?(options) ? ' ' : " #{union} "
36
33
  [tens(numbers[1], options), connector, ones(numbers[0], options)].join
37
34
  end
38
35
 
39
36
  def hundreds(number, options = {})
40
- return t(:one_hundred) if options[:is_one_hundred] && !(ordinal? options)
41
- translated = t([options[:prefix], :hundreds, options[:gender]].join('.'))[number - 1]
42
- return translated if ordinal? options
43
- options[:is_hundred] ? translated : translated + " #{union}"
37
+ return t(:one_hundred) if options[:is_one_hundred] && !ordinal?(options)
38
+ hundreds = t([options[:prefix], :hundreds, options[:gender]].join('.'))[number]
39
+ return hundreds if ordinal?(options) || options[:is_hundred]
40
+ [hundreds, union].join(' ')
44
41
  end
45
42
 
46
43
  def megs(capacity, options = {})
47
- return t([options[:prefix], :mega, options[:gender]].join('.'))[capacity] if ordinal? options
48
-
49
- options[:is_one] = false if options[:is_one].nil?
50
- connector = " #{union}"
51
- connector = ',' if options[:is_with_comma]
52
- suffix = options[:is_opaque] ? '' : connector
53
- suffix = options[:is_without_connector] ? '' : suffix
54
- (options[:is_one] ? t(:mega)[capacity] : t(:megas)[capacity]) + suffix
44
+ return t([options[:prefix], :mega, options[:gender]].join('.'))[capacity] if ordinal?(options)
45
+ return super(capacity, options) if options[:is_opaque] || options[:is_without_connector]
46
+ suffix = options[:is_with_comma] ? ',' : " #{union}"
47
+ super(capacity, options) + suffix
55
48
  end
56
49
 
57
- def micros(capacity, number, separator = t('micro_prefix.separator'))
50
+ def micros(capacity, number = nil)
58
51
  micro, prefix = capacity
59
52
  micros = number ? t(micro(micro), count: number) : micro(micro)
60
- [micro_prefix(prefix, number), micros].compact.join(" #{separator} ")
53
+ [micro_prefix(prefix, number), micros].compact.join(t('micro_prefix.union'))
61
54
  end
62
55
 
63
56
  def micro_prefix(capacity, number)