numbers_and_words 0.10.0 → 0.10.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (36) hide show
  1. checksums.yaml +6 -14
  2. data/CHANGELOG.md +167 -0
  3. data/README.rdoc +22 -10
  4. data/lib/numbers_and_words/helper_classes/array_extensions/helpers.rb +0 -8
  5. data/lib/numbers_and_words/i18n/locales/numbers.en.yml +16 -4
  6. data/lib/numbers_and_words/i18n/locales/numbers.es.yml +6 -6
  7. data/lib/numbers_and_words/i18n/locales/numbers.fr.yml +13 -12
  8. data/lib/numbers_and_words/i18n/locales/numbers.hu.yml +0 -1
  9. data/lib/numbers_and_words/i18n/locales/numbers.ka.yml +23 -0
  10. data/lib/numbers_and_words/i18n/locales/numbers.lt.yml +10 -10
  11. data/lib/numbers_and_words/i18n/locales/numbers.lv.yml +3 -3
  12. data/lib/numbers_and_words/i18n/locales/numbers.pt.yml +13 -0
  13. data/lib/numbers_and_words/i18n/pluralization.rb +0 -1
  14. data/lib/numbers_and_words/i18n/plurals/fr.rb +1 -1
  15. data/lib/numbers_and_words/strategies/figures_converter/languages.rb +2 -0
  16. data/lib/numbers_and_words/strategies/figures_converter/languages/en.rb +16 -0
  17. data/lib/numbers_and_words/strategies/figures_converter/languages/es.rb +14 -5
  18. data/lib/numbers_and_words/strategies/figures_converter/languages/ka.rb +43 -0
  19. data/lib/numbers_and_words/strategies/figures_converter/languages/lv.rb +1 -9
  20. data/lib/numbers_and_words/strategies/figures_converter/languages/pt.rb +30 -0
  21. data/lib/numbers_and_words/strategies/figures_converter/languages/tr.rb +18 -0
  22. data/lib/numbers_and_words/strategies/figures_converter/options/en.rb +2 -1
  23. data/lib/numbers_and_words/strategies/figures_converter/options/en/pronounced.rb +76 -0
  24. data/lib/numbers_and_words/strategies/figures_converter/options/en_gb.rb +1 -0
  25. data/lib/numbers_and_words/strategies/figures_converter/options/en_gb/pronounced.rb +12 -0
  26. data/lib/numbers_and_words/translations.rb +2 -0
  27. data/lib/numbers_and_words/translations/es.rb +6 -1
  28. data/lib/numbers_and_words/translations/et.rb +1 -5
  29. data/lib/numbers_and_words/translations/hu.rb +0 -4
  30. data/lib/numbers_and_words/translations/ka.rb +72 -0
  31. data/lib/numbers_and_words/translations/pt.rb +27 -0
  32. data/lib/numbers_and_words/translations/tr.rb +9 -0
  33. data/lib/numbers_and_words/version.rb +1 -1
  34. data/lib/numbers_and_words/wrappers/float.rb +1 -9
  35. metadata +25 -16
  36. data/lib/numbers_and_words/i18n/plurals/es.rb +0 -11
@@ -13,40 +13,40 @@ lt:
13
13
  millions:
14
14
  one: milijonas
15
15
  ones: milijonai
16
- other: milijonø
16
+ other: milijonų
17
17
  billions:
18
18
  one: bilijonas
19
19
  ones: bilijonai
20
- other: bilijonø
20
+ other: bilijonų
21
21
  trillions:
22
22
  one: trilijonas
23
23
  ones: trilijonai
24
- other: trilijonø
24
+ other: trilijonų
25
25
  quadrillions:
26
26
  one: kvadrilijonas
27
27
  ones: kvadrilijonai
28
- other: kvadrilijonø
28
+ other: kvadrilijonų
29
29
  quintillions:
30
30
  one: kvintilijonas
31
31
  ones: kvadrilijonai
32
- other: kvadrilijonø
32
+ other: kvadrilijonų
33
33
  sextillions:
34
34
  one: sekstilijonas
35
35
  ones: sekstilijonai
36
- other: sekstilijonø
36
+ other: sekstilijonų
37
37
  septillions:
38
38
  one: septilijonas
39
39
  ones: septilijonai
40
- other: septilijonø
40
+ other: septilijonų
41
41
  octillions:
42
42
  one: oktilijonas
43
43
  ones: oktilijonai
44
- other: oktilijonø
44
+ other: oktilijonų
45
45
  nonillions:
46
46
  one: nonilijonas
47
47
  ones: nonilijonai
48
- other: nonilijonø
48
+ other: nonilijonų
49
49
  decillions:
50
50
  one: decilijonas
51
51
  ones: decilijonai
52
- other: decilijonø
52
+ other: decilijonų
@@ -4,10 +4,10 @@ lv:
4
4
  teens: [desmit, vienpadsmit, divpadsmit, trīspadsmit, četrpadsmit, piecpadsmit, sešpadsmit, septiņpadsmit, astoņpadsmit, deviņpadsmit]
5
5
  tens: [nulle, desmit, divdesmit, trīsdesmit, četrdesmit, piecdesmit, sešdesmit, septiņdesmit, astoņdesmit, deviņdesmit]
6
6
  mega: [ones, thousands, millions, billions, trillions, quadrillions, quintillion, sextillions, septillions, octillions, nonillions, decillions]
7
- hundreds: [simtu, divi simti, trīs simti, četri simti, pieci simti, seši simti, septiņi simti, astoņi simti, deviņi simti]
8
- one_hundred: simts
7
+ hundreds: [viens simts, divi simti, trīs simti, četri simti, pieci simti, seši simti, septiņi simti, astoņi simti, deviņi simti]
8
+ one_hundred: viens simts
9
9
  thousands:
10
- one: tūkstots
10
+ one: tūkstotis
11
11
  other: tūkstoši
12
12
  millions:
13
13
  one: miljons
@@ -0,0 +1,13 @@
1
+ pt:
2
+ numbers:
3
+ union: e
4
+ ones: [zero, um, dois, três, quatro, cinco, seis, sete, oito, nove]
5
+ ones_twenties: [zero, um, dois, três, quatro, cinco, seis, sete, oito, nove]
6
+ one: um
7
+ teens: [dez, onze, doze, treze, quatorze, quinze, dezesseis, dezessete, dezoito, dezenove]
8
+ tens: [zero, dez, vinte, trinta, quarenta, cinquenta, sessenta, setenta, oitenta, noventa]
9
+ twenty: vinte
10
+ hundreds: [cento, duzentos, trezentos, quatrocentos, quinhentos, seiscentos, setecentos, oitocentos, novecentos]
11
+ one_hundred: cem
12
+ mega: [_, mil, milhão, bilhão, trilhão, quadrilhão, quinquilhão]
13
+ megas: [_, mil, milhões, bilhões, trilhões, quadrilhões, quinquilhões]
@@ -1,7 +1,6 @@
1
1
  require 'numbers_and_words/i18n/plurals/ru'
2
2
  require 'numbers_and_words/i18n/plurals/ua'
3
3
  require 'numbers_and_words/i18n/plurals/fr'
4
- require 'numbers_and_words/i18n/plurals/es'
5
4
  require 'numbers_and_words/i18n/plurals/lv'
6
5
  require 'numbers_and_words/i18n/plurals/lt'
7
6
 
@@ -2,7 +2,7 @@ module NumbersAndWords
2
2
  module I18n
3
3
  module Plurals
4
4
  module Fr
5
- RULE = lambda { |n| one_conditions(n) ? :one : :many }
5
+ RULE = lambda { |n| one_conditions(n) ? :one : :other }
6
6
 
7
7
  extend self
8
8
 
@@ -23,7 +23,9 @@ require 'numbers_and_words/strategies/figures_converter/languages/families/cyril
23
23
 
24
24
  require 'numbers_and_words/strategies/figures_converter/languages/ru'
25
25
  require 'numbers_and_words/strategies/figures_converter/languages/ua'
26
+ require 'numbers_and_words/strategies/figures_converter/languages/pt'
26
27
 
28
+ require 'numbers_and_words/strategies/figures_converter/languages/ka'
27
29
 
28
30
  module NumbersAndWords
29
31
  module Strategies
@@ -26,6 +26,22 @@ module NumbersAndWords
26
26
  })
27
27
  end
28
28
 
29
+ def strings_logic
30
+ if @options.pronounced.active?
31
+ @options.pronounced.process self, @figures
32
+ else
33
+ if @figures.capacity_count
34
+ number_without_capacity_to_words + complex_number_to_words
35
+ elsif @figures.hundreds
36
+ hundreds_number_to_words
37
+ elsif @figures.tens or @figures.ones
38
+ simple_number_to_words
39
+ else
40
+ []
41
+ end
42
+ end
43
+ end
44
+
29
45
  def maybe_hyphen_separator
30
46
  @options.remove_hyphen.result
31
47
  end
@@ -11,18 +11,27 @@ module NumbersAndWords
11
11
  words.push megs(capacity_words) unless capacity_words.empty?
12
12
 
13
13
  if 0 < @current_capacity
14
- # eg 1000000 should be "un millon" not "uno millon"
14
+ # eg 1000000 should be "un millón" not "uno millón"
15
15
  # 501000 should be "quinientos un mil" not "quinientos uno mil"
16
- # so we replace "uno" with "un" throughout
16
+ # 1000 should be "mil" not "uno mil"
17
+ # so we replace "uno" with "un" throughout or delete it if that is the case
17
18
 
18
- capacity_words = capacity_words.map{|word|
19
- word.gsub( @translations.ones(1), @translations.one )
20
- }
19
+ capacity_words = capacity_words.map { |word|
20
+ word.gsub(@translations.ones(1), @translations.one) unless is_a_thousand? and is_a_one?
21
+ }.compact
21
22
  end
22
23
 
23
24
  words + capacity_words
24
25
  end
25
26
 
27
+ def is_a_one?
28
+ [translations.ones(1)] == words_in_capacity(@current_capacity)
29
+ end
30
+
31
+ def is_a_thousand?
32
+ @current_capacity.odd?
33
+ end
34
+
26
35
  def hundreds
27
36
  super({:is_hundred => (figures[1,2] == [0,1] && simple_number_to_words.empty?)})
28
37
  end
@@ -0,0 +1,43 @@
1
+ module NumbersAndWords
2
+ module Strategies
3
+ module FiguresConverter
4
+ module Languages
5
+ class Ka < Base
6
+ include Families::Latin
7
+
8
+ private
9
+
10
+ def capacity_iteration
11
+ words = []
12
+ capacity_words = words_in_capacity(@current_capacity)
13
+ words.push(megs) unless capacity_words.empty?
14
+ words += capacity_words unless is_a_thousand? and is_a_one?
15
+ words
16
+ end
17
+
18
+ def is_a_one?
19
+ [translations.ones(1)] == words_in_capacity(@current_capacity)
20
+ end
21
+
22
+ def is_a_thousand?
23
+ FiguresArray::THOUSAND_CAPACITY == @current_capacity
24
+ end
25
+
26
+ def hundreds
27
+ super({only_hundreds: figures[0, 2] == [0, 0]})
28
+ end
29
+
30
+ def megs
31
+ if @figures.hundreds || @figures.tens || @figures.ones
32
+ prefix = :partials
33
+ else
34
+ prefix = nil
35
+ end
36
+
37
+ super(prefix: prefix)
38
+ end
39
+ end
40
+ end
41
+ end
42
+ end
43
+ end
@@ -11,18 +11,10 @@ module NumbersAndWords
11
11
  words = []
12
12
  capacity_words = words_in_capacity(@current_capacity)
13
13
  words.push(megs) unless capacity_words.empty?
14
- words += capacity_words unless is_a_thousand? and is_a_one?
14
+ words += capacity_words
15
15
  words
16
16
  end
17
17
 
18
- def is_a_one?
19
- [translations.ones(1)] == words_in_capacity(@current_capacity)
20
- end
21
-
22
- def is_a_thousand?
23
- FiguresArray::THOUSAND_CAPACITY == @current_capacity
24
- end
25
-
26
18
  def hundreds
27
19
  super({:is_hundred => (figures[1,2] == [0,1] && simple_number_to_words.empty?)})
28
20
  end
@@ -0,0 +1,30 @@
1
+ module NumbersAndWords
2
+ module Strategies
3
+ module FiguresConverter
4
+ module Languages
5
+ class Pt < Base
6
+ include Families::Latin
7
+
8
+ def hundreds
9
+ super({:is_hundred => (is_hundred?), :is_one_hundred => (is_one_hundred?)})
10
+ end
11
+
12
+ def megs
13
+ super({:is_one => words_in_capacity(@current_capacity) == [@translations.ones(1)]})
14
+ end
15
+
16
+ private
17
+
18
+ def is_hundred?
19
+ figures[0] == 0 && figures[1] == 0 && simple_number_to_words.empty?
20
+ end
21
+
22
+ def is_one_hundred?
23
+ is_hundred? && figures[2] == 1
24
+ end
25
+
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
@@ -4,6 +4,24 @@ module NumbersAndWords
4
4
  module Languages
5
5
  class Tr < Base
6
6
  include Families::Latin
7
+
8
+ private
9
+
10
+ def capacity_iteration
11
+ words = []
12
+ capacity_words = words_in_capacity(@current_capacity)
13
+ words.push(megs) unless capacity_words.empty?
14
+ words += capacity_words unless is_a_thousand? and is_a_one?
15
+ words
16
+ end
17
+
18
+ def is_a_one?
19
+ [translations.ones(1)] == words_in_capacity(@current_capacity)
20
+ end
21
+
22
+ def is_a_thousand?
23
+ FiguresArray::THOUSAND_CAPACITY == @current_capacity
24
+ end
7
25
  end
8
26
  end
9
27
  end
@@ -1,4 +1,5 @@
1
1
  require 'numbers_and_words/strategies/figures_converter/options/en/hundreds_with_union'
2
2
  require 'numbers_and_words/strategies/figures_converter/options/en/remove_hyphen'
3
3
  require 'numbers_and_words/strategies/figures_converter/options/en/ordinal'
4
- require 'numbers_and_words/strategies/figures_converter/options/en/remove_zero'
4
+ require 'numbers_and_words/strategies/figures_converter/options/en/pronounced'
5
+ require 'numbers_and_words/strategies/figures_converter/options/en/remove_zero'
@@ -0,0 +1,76 @@
1
+ module NumbersAndWords
2
+ module Strategies
3
+ module FiguresConverter
4
+ module Options
5
+ module En
6
+ class Pronounced
7
+ attr_accessor :strategy, :options
8
+
9
+ def initialize proxy, *args, &block
10
+ @strategy = proxy.strategy
11
+ @options = proxy.options
12
+ end
13
+
14
+
15
+ def result
16
+ active? ? 'PRONOUNCED' : 'NOTPRONOUNCED'
17
+ end
18
+
19
+ def active?
20
+ @options[:pronounced]
21
+ end
22
+
23
+ def process language, figures
24
+ if figures.to_a.count > 4
25
+ language.number_without_capacity_to_words + language.complex_number_to_words
26
+ elsif figures.capacity_count
27
+ handle_thousands language, figures
28
+ elsif figures.hundreds
29
+ handle_hundreds language, figures
30
+ elsif figures.tens or figures.ones
31
+ language.simple_number_to_words
32
+ else
33
+ []
34
+ end
35
+ end
36
+
37
+ def handle_thousands language, figures
38
+ units, tens, hundreds, thousands = *figures.to_a.dup
39
+ if hundreds == 0
40
+ language.number_without_capacity_to_words + language.complex_number_to_words
41
+ else
42
+ result = tens_with_oh language, figures
43
+ result.push "#{thousands}#{hundreds}".to_i.to_words
44
+ end
45
+ end
46
+
47
+ def handle_hundreds language, figures
48
+ units, tens, hundreds = *figures.to_a.dup
49
+ result = tens_with_oh language, figures
50
+ result.push hundreds.to_words
51
+ end
52
+
53
+ def tens_with_oh language, figures
54
+ units, tens = *figures.to_a.dup
55
+ result = []
56
+ if tens == 0
57
+ if units == 0
58
+ result.push 'hundred'
59
+ else
60
+ result.push language.ones
61
+ result.push 'oh'
62
+ end
63
+ else
64
+ if figures.teens
65
+ result.push language.teens
66
+ elsif figures.tens
67
+ result.push language.complex_tens
68
+ end
69
+ end
70
+ end
71
+ end
72
+ end
73
+ end
74
+ end
75
+ end
76
+ end
@@ -1,4 +1,5 @@
1
1
  require 'numbers_and_words/strategies/figures_converter/options/en_gb/hundreds_with_union'
2
2
  require 'numbers_and_words/strategies/figures_converter/options/en_gb/remove_hyphen'
3
3
  require 'numbers_and_words/strategies/figures_converter/options/en_gb/ordinal'
4
+ require 'numbers_and_words/strategies/figures_converter/options/en_gb/pronounced'
4
5
  require 'numbers_and_words/strategies/figures_converter/options/en_gb/remove_zero'
@@ -0,0 +1,12 @@
1
+ module NumbersAndWords
2
+ module Strategies
3
+ module FiguresConverter
4
+ module Options
5
+ module EnGb
6
+ class Pronounced < En::Pronounced
7
+ end
8
+ end
9
+ end
10
+ end
11
+ end
12
+ end
@@ -18,6 +18,8 @@ require 'numbers_and_words/translations/es'
18
18
  require 'numbers_and_words/translations/lv'
19
19
  require 'numbers_and_words/translations/lt'
20
20
  require 'numbers_and_words/translations/de'
21
+ require 'numbers_and_words/translations/pt'
22
+ require 'numbers_and_words/translations/ka'
21
23
 
22
24
  module NumbersAndWords
23
25
  module Translations
@@ -13,6 +13,10 @@ module NumbersAndWords
13
13
  t(:ones)[number]
14
14
  end
15
15
 
16
+ def ones_twenties number, options = {}
17
+ t(:ones_twenties)[number]
18
+ end
19
+
16
20
  def tens numbers, options = {}
17
21
  options[:alone] = true if options[:alone].nil?
18
22
  (numbers == TENS_CASE && options[:alone]) ? t(:twenty) : super(numbers)
@@ -20,7 +24,8 @@ module NumbersAndWords
20
24
 
21
25
  def tens_with_ones numbers, options = {}
22
26
  inter = numbers[1] == TENS_CASE ? "" : " y "
23
- [tens(numbers[1], :alone => false), ones(numbers[0])].join inter
27
+ ones_number = numbers[1] == TENS_CASE ? ones_twenties(numbers[0]) : ones(numbers[0])
28
+ [tens(numbers[1], :alone => false), ones_number].join inter
24
29
  end
25
30
 
26
31
  def hundreds number, options = {}
@@ -4,11 +4,7 @@ module NumbersAndWords
4
4
  include NumbersAndWords::Translations::Families::Latin
5
5
 
6
6
  def tens_with_ones numbers, options = {}
7
- if numbers[1] == 1
8
- [ones(numbers[0]), tens(numbers[1], :alone => false)].join ''
9
- else
10
- [tens(numbers[1], :alone => false), ones(numbers[0])].join ' '
11
- end
7
+ [tens(numbers[1], :alone => false), ones(numbers[0])].join ' '
12
8
  end
13
9
 
14
10
  def hundreds number, options = {}
@@ -17,10 +17,6 @@ module NumbersAndWords
17
17
  def micros capacity, number = nil, separator = ''
18
18
  super capacity, nil, separator
19
19
  end
20
-
21
- def union
22
- t :union
23
- end
24
20
  end
25
21
  end
26
22
  end