numbers_and_words 0.11.0 → 0.11.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/numbers_and_words/core_ext/array.rb +2 -2
- data/lib/numbers_and_words/core_ext/float.rb +1 -1
- data/lib/numbers_and_words/core_ext/integer.rb +1 -1
- data/lib/numbers_and_words/helper_classes.rb +1 -1
- data/lib/numbers_and_words/helper_classes/array_extensions/helpers.rb +11 -12
- data/lib/numbers_and_words/helper_classes/figures_array.rb +1 -4
- data/lib/numbers_and_words/helper_classes/words_array.rb +2 -4
- data/lib/numbers_and_words/i18n.rb +4 -4
- data/lib/numbers_and_words/i18n/initialization.rb +2 -2
- data/lib/numbers_and_words/i18n/locales/numbers.en.yml +3 -3
- data/lib/numbers_and_words/i18n/locales/numbers.es.yml +86 -25
- data/lib/numbers_and_words/i18n/locales/numbers.fr.yml +54 -1
- data/lib/numbers_and_words/i18n/locales/numbers.pt-BR.yml +4 -4
- data/lib/numbers_and_words/i18n/locales/numbers.pt.yml +0 -1
- data/lib/numbers_and_words/i18n/pluralization.rb +2 -3
- data/lib/numbers_and_words/i18n/plurals/fr.rb +3 -3
- data/lib/numbers_and_words/i18n/plurals/lt.rb +11 -8
- data/lib/numbers_and_words/i18n/plurals/lv.rb +3 -3
- data/lib/numbers_and_words/i18n/plurals/ru.rb +15 -10
- data/lib/numbers_and_words/strategies.rb +1 -1
- data/lib/numbers_and_words/strategies/array_joiner.rb +1 -2
- data/lib/numbers_and_words/strategies/array_joiner/languages.rb +3 -1
- data/lib/numbers_and_words/strategies/array_joiner/languages/base.rb +1 -1
- data/lib/numbers_and_words/strategies/array_joiner/languages/es.rb +10 -0
- data/lib/numbers_and_words/strategies/array_joiner/languages/families/base.rb +0 -1
- data/lib/numbers_and_words/strategies/array_joiner/languages/fr.rb +10 -0
- data/lib/numbers_and_words/strategies/figures_converter.rb +1 -2
- data/lib/numbers_and_words/strategies/figures_converter/decorators.rb +8 -6
- data/lib/numbers_and_words/strategies/figures_converter/decorators/base.rb +2 -2
- data/lib/numbers_and_words/strategies/figures_converter/decorators/en/base.rb +1 -1
- data/lib/numbers_and_words/strategies/figures_converter/decorators/en/fractional.rb +2 -3
- data/lib/numbers_and_words/strategies/figures_converter/decorators/en/integral.rb +1 -1
- data/lib/numbers_and_words/strategies/figures_converter/decorators/es.rb +3 -0
- data/lib/numbers_and_words/strategies/figures_converter/decorators/es/base.rb +12 -0
- data/lib/numbers_and_words/strategies/figures_converter/decorators/es/fractional.rb +38 -0
- data/lib/numbers_and_words/strategies/figures_converter/decorators/es/integral.rb +12 -0
- data/lib/numbers_and_words/strategies/figures_converter/decorators/fr.rb +3 -0
- data/lib/numbers_and_words/strategies/figures_converter/decorators/fr/base.rb +12 -0
- data/lib/numbers_and_words/strategies/figures_converter/decorators/fr/fractional.rb +37 -0
- data/lib/numbers_and_words/strategies/figures_converter/decorators/fr/integral.rb +12 -0
- data/lib/numbers_and_words/strategies/figures_converter/decorators/hu.rb +1 -1
- data/lib/numbers_and_words/strategies/figures_converter/decorators/hu/base.rb +1 -1
- data/lib/numbers_and_words/strategies/figures_converter/decorators/hu/fractional.rb +2 -3
- data/lib/numbers_and_words/strategies/figures_converter/decorators/hu/integral.rb +1 -1
- data/lib/numbers_and_words/strategies/figures_converter/decorators/pt-BR/fractional.rb +1 -2
- data/lib/numbers_and_words/strategies/figures_converter/decorators/ru/base.rb +1 -1
- data/lib/numbers_and_words/strategies/figures_converter/decorators/ru/fractional.rb +2 -3
- data/lib/numbers_and_words/strategies/figures_converter/decorators/ru/integral.rb +1 -2
- data/lib/numbers_and_words/strategies/figures_converter/decorators/ua/base.rb +1 -1
- data/lib/numbers_and_words/strategies/figures_converter/decorators/ua/fractional.rb +2 -3
- data/lib/numbers_and_words/strategies/figures_converter/decorators/ua/integral.rb +1 -2
- data/lib/numbers_and_words/strategies/figures_converter/languages.rb +1 -1
- data/lib/numbers_and_words/strategies/figures_converter/languages/base.rb +1 -1
- data/lib/numbers_and_words/strategies/figures_converter/languages/de.rb +9 -9
- data/lib/numbers_and_words/strategies/figures_converter/languages/en-GB.rb +1 -1
- data/lib/numbers_and_words/strategies/figures_converter/languages/en.rb +17 -19
- data/lib/numbers_and_words/strategies/figures_converter/languages/es.rb +50 -25
- data/lib/numbers_and_words/strategies/figures_converter/languages/et.rb +1 -2
- data/lib/numbers_and_words/strategies/figures_converter/languages/families/base.rb +5 -5
- data/lib/numbers_and_words/strategies/figures_converter/languages/families/cyrillic.rb +5 -5
- data/lib/numbers_and_words/strategies/figures_converter/languages/families/helpers.rb +10 -14
- data/lib/numbers_and_words/strategies/figures_converter/languages/fr.rb +7 -7
- data/lib/numbers_and_words/strategies/figures_converter/languages/hu.rb +8 -8
- data/lib/numbers_and_words/strategies/figures_converter/languages/ka.rb +8 -10
- data/lib/numbers_and_words/strategies/figures_converter/languages/lt.rb +6 -6
- data/lib/numbers_and_words/strategies/figures_converter/languages/lv.rb +2 -2
- data/lib/numbers_and_words/strategies/figures_converter/languages/pt-BR.rb +24 -26
- data/lib/numbers_and_words/strategies/figures_converter/languages/pt.rb +6 -7
- data/lib/numbers_and_words/strategies/figures_converter/languages/tr.rb +4 -4
- data/lib/numbers_and_words/strategies/figures_converter/options.rb +6 -5
- data/lib/numbers_and_words/strategies/figures_converter/options/en-GB/hundreds_with_union.rb +1 -1
- data/lib/numbers_and_words/strategies/figures_converter/options/en-GB/ordinal.rb +1 -1
- data/lib/numbers_and_words/strategies/figures_converter/options/en-GB/remove_hyphen.rb +1 -1
- data/lib/numbers_and_words/strategies/figures_converter/options/en-GB/remove_zero.rb +1 -1
- data/lib/numbers_and_words/strategies/figures_converter/options/en/hundreds_with_union.rb +3 -3
- data/lib/numbers_and_words/strategies/figures_converter/options/en/ordinal.rb +3 -3
- data/lib/numbers_and_words/strategies/figures_converter/options/en/pronounced.rb +14 -23
- data/lib/numbers_and_words/strategies/figures_converter/options/en/remove_hyphen.rb +2 -3
- data/lib/numbers_and_words/strategies/figures_converter/options/en/remove_zero.rb +2 -2
- data/lib/numbers_and_words/strategies/figures_converter/options/es.rb +3 -0
- data/lib/numbers_and_words/strategies/figures_converter/options/es/apocopated.rb +28 -0
- data/lib/numbers_and_words/strategies/figures_converter/options/es/gender.rb +28 -0
- data/lib/numbers_and_words/strategies/figures_converter/options/es/remove_zero.rb +28 -0
- data/lib/numbers_and_words/strategies/figures_converter/options/hu/ordinal.rb +3 -3
- data/lib/numbers_and_words/strategies/figures_converter/options/pt-BR/gender.rb +2 -2
- data/lib/numbers_and_words/strategies/figures_converter/options/pt-BR/ordinal.rb +1 -1
- data/lib/numbers_and_words/strategies/figures_converter/options/pt-BR/remove_zero.rb +1 -1
- data/lib/numbers_and_words/strategies/figures_converter/options/ru/gender.rb +2 -2
- data/lib/numbers_and_words/strategies/figures_converter/options/ua/gender.rb +2 -2
- data/lib/numbers_and_words/translations/base.rb +2 -2
- data/lib/numbers_and_words/translations/de.rb +5 -5
- data/lib/numbers_and_words/translations/es.rb +29 -24
- data/lib/numbers_and_words/translations/et.rb +3 -3
- data/lib/numbers_and_words/translations/extensions/fraction_significance.rb +4 -5
- data/lib/numbers_and_words/translations/families/base.rb +8 -8
- data/lib/numbers_and_words/translations/families/cyrillic.rb +6 -6
- data/lib/numbers_and_words/translations/families/latin.rb +6 -6
- data/lib/numbers_and_words/translations/fr.rb +16 -8
- data/lib/numbers_and_words/translations/hu.rb +3 -3
- data/lib/numbers_and_words/translations/it.rb +3 -3
- data/lib/numbers_and_words/translations/ka.rb +13 -13
- data/lib/numbers_and_words/translations/lt.rb +4 -5
- data/lib/numbers_and_words/translations/lv.rb +4 -5
- data/lib/numbers_and_words/translations/nl.rb +3 -3
- data/lib/numbers_and_words/translations/pt-BR.rb +18 -18
- data/lib/numbers_and_words/translations/pt.rb +4 -5
- data/lib/numbers_and_words/translations/ru.rb +5 -5
- data/lib/numbers_and_words/translations/se.rb +2 -2
- data/lib/numbers_and_words/translations/tr.rb +3 -4
- data/lib/numbers_and_words/translations/ua.rb +3 -3
- data/lib/numbers_and_words/version.rb +1 -1
- data/lib/numbers_and_words/wrappers.rb +1 -1
- data/lib/numbers_and_words/wrappers/float.rb +9 -9
- data/lib/numbers_and_words/wrappers/integer.rb +3 -3
- metadata +16 -4
- data/lib/numbers_and_words/helper_classes/array_extensions/validations.rb +0 -19
- data/lib/numbers_and_words/i18n/plurals/pt-BR.rb +0 -15
@@ -4,7 +4,6 @@ module NumbersAndWords
|
|
4
4
|
module Decorators
|
5
5
|
module Hu
|
6
6
|
class Fractional < Base
|
7
|
-
|
8
7
|
def run
|
9
8
|
"#{super} #{fraction_significance}"
|
10
9
|
end
|
@@ -16,7 +15,7 @@ module NumbersAndWords
|
|
16
15
|
end
|
17
16
|
|
18
17
|
def full_fraction
|
19
|
-
(0..zero_length).inject(figures.clone) { |result,
|
18
|
+
(0..zero_length).inject(figures.clone) { |result, _el| result.unshift '0' }.to_figures
|
20
19
|
end
|
21
20
|
|
22
21
|
def figures
|
@@ -35,4 +34,4 @@ module NumbersAndWords
|
|
35
34
|
end
|
36
35
|
end
|
37
36
|
end
|
38
|
-
end
|
37
|
+
end
|
@@ -4,7 +4,6 @@ module NumbersAndWords
|
|
4
4
|
module Decorators
|
5
5
|
module PtBr
|
6
6
|
class Fractional < Base
|
7
|
-
|
8
7
|
def run
|
9
8
|
"#{super} #{fraction_significance}"
|
10
9
|
end
|
@@ -16,7 +15,7 @@ module NumbersAndWords
|
|
16
15
|
end
|
17
16
|
|
18
17
|
def full_fraction
|
19
|
-
(0..zero_length).inject(figures.clone) { |result,
|
18
|
+
(0..zero_length).inject(figures.clone) { |result, _el| result.unshift 0 }.to_figures
|
20
19
|
end
|
21
20
|
|
22
21
|
def figures
|
@@ -4,7 +4,6 @@ module NumbersAndWords
|
|
4
4
|
module Decorators
|
5
5
|
module Ru
|
6
6
|
class Fractional < Base
|
7
|
-
|
8
7
|
def run
|
9
8
|
@options[:gender] = :female
|
10
9
|
"#{super} #{fraction_significance}"
|
@@ -17,7 +16,7 @@ module NumbersAndWords
|
|
17
16
|
end
|
18
17
|
|
19
18
|
def full_fraction
|
20
|
-
(0..zero_length).inject(figures.clone) { |result,
|
19
|
+
(0..zero_length).inject(figures.clone) { |result, _el| result.unshift '0' }.to_figures
|
21
20
|
end
|
22
21
|
|
23
22
|
def figures
|
@@ -36,4 +35,4 @@ module NumbersAndWords
|
|
36
35
|
end
|
37
36
|
end
|
38
37
|
end
|
39
|
-
end
|
38
|
+
end
|
@@ -4,7 +4,6 @@ module NumbersAndWords
|
|
4
4
|
module Decorators
|
5
5
|
module Ua
|
6
6
|
class Fractional < Base
|
7
|
-
|
8
7
|
def run
|
9
8
|
@options[:gender] = :female
|
10
9
|
"#{super} #{fraction_significance}"
|
@@ -17,7 +16,7 @@ module NumbersAndWords
|
|
17
16
|
end
|
18
17
|
|
19
18
|
def full_fraction
|
20
|
-
(0..zero_length).inject(figures.clone) { |result,
|
19
|
+
(0..zero_length).inject(figures.clone) { |result, _el| result.unshift '0' }.to_figures
|
21
20
|
end
|
22
21
|
|
23
22
|
def figures
|
@@ -36,4 +35,4 @@ module NumbersAndWords
|
|
36
35
|
end
|
37
36
|
end
|
38
37
|
end
|
39
|
-
end
|
38
|
+
end
|
@@ -6,7 +6,7 @@ module NumbersAndWords
|
|
6
6
|
include Families::Latin
|
7
7
|
|
8
8
|
def print_words
|
9
|
-
|
9
|
+
complex_part.count > 1 ? print_megs_words : @strings.flatten.reverse.join('')
|
10
10
|
end
|
11
11
|
|
12
12
|
def print_megs_words
|
@@ -14,14 +14,14 @@ module NumbersAndWords
|
|
14
14
|
end
|
15
15
|
|
16
16
|
def complex_number_to_words
|
17
|
-
(1..@figures.capacity_count).map
|
17
|
+
(1..@figures.capacity_count).map do |capacity|
|
18
18
|
@current_capacity = capacity
|
19
19
|
capacity_iteration
|
20
|
-
|
20
|
+
end
|
21
21
|
end
|
22
22
|
|
23
23
|
def ones
|
24
|
-
super(:
|
24
|
+
super(postfix: postfix)
|
25
25
|
end
|
26
26
|
|
27
27
|
def postfix
|
@@ -33,15 +33,15 @@ module NumbersAndWords
|
|
33
33
|
end
|
34
34
|
|
35
35
|
def megs
|
36
|
-
super({:
|
36
|
+
super({ number: @figures.number_in_capacity(@current_capacity) })
|
37
37
|
end
|
38
38
|
|
39
39
|
private
|
40
40
|
|
41
41
|
def print_megs
|
42
|
-
complex_part[1..-1].map
|
42
|
+
complex_part[1..-1].map do |el|
|
43
43
|
[el[1..-1].to_a.reverse.join(''), el.first].join(' ')
|
44
|
-
|
44
|
+
end.reject(&:empty?).reverse.join(' ')
|
45
45
|
end
|
46
46
|
|
47
47
|
def print_other
|
@@ -53,7 +53,7 @@ module NumbersAndWords
|
|
53
53
|
end
|
54
54
|
|
55
55
|
def simple_part
|
56
|
-
@strings.
|
56
|
+
@strings.reject { |f| f.is_a?(Array) }
|
57
57
|
end
|
58
58
|
|
59
59
|
def complex_part
|
@@ -63,4 +63,4 @@ module NumbersAndWords
|
|
63
63
|
end
|
64
64
|
end
|
65
65
|
end
|
66
|
-
end
|
66
|
+
end
|
@@ -5,40 +5,38 @@ module NumbersAndWords
|
|
5
5
|
class En < Base
|
6
6
|
include Families::Latin
|
7
7
|
|
8
|
-
[
|
9
|
-
define_method(method_name)
|
10
|
-
super({:
|
11
|
-
|
8
|
+
%i[ones teens tens megs].each do |method_name|
|
9
|
+
define_method(method_name) do
|
10
|
+
super({ prefix: maybe_ordinal(method_name) })
|
11
|
+
end
|
12
12
|
end
|
13
13
|
|
14
14
|
def hundreds
|
15
|
-
maybe_union_after_hundreds super({:
|
15
|
+
maybe_union_after_hundreds super({ prefix: maybe_ordinal(:hundreds) })
|
16
16
|
end
|
17
17
|
|
18
18
|
def zero
|
19
|
-
super({:
|
19
|
+
super({ prefix: maybe_ordinal(:zero) }) unless maybe_remove_zero
|
20
20
|
end
|
21
21
|
|
22
22
|
def tens_with_ones
|
23
23
|
super({
|
24
|
-
:
|
25
|
-
:
|
24
|
+
separator: maybe_hyphen_separator,
|
25
|
+
prefix: maybe_ordinal(:tens_with_ones)
|
26
26
|
})
|
27
27
|
end
|
28
28
|
|
29
29
|
def strings_logic
|
30
30
|
if @options.pronounced.active?
|
31
31
|
@options.pronounced.process self, @figures
|
32
|
+
elsif @figures.capacity_count
|
33
|
+
number_without_capacity_to_words + complex_number_to_words
|
34
|
+
elsif @figures.hundreds
|
35
|
+
hundreds_number_to_words
|
36
|
+
elsif @figures.tens || @figures.ones
|
37
|
+
simple_number_to_words
|
32
38
|
else
|
33
|
-
|
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
|
39
|
+
[]
|
42
40
|
end
|
43
41
|
end
|
44
42
|
|
@@ -46,11 +44,11 @@ module NumbersAndWords
|
|
46
44
|
@options.remove_hyphen.result
|
47
45
|
end
|
48
46
|
|
49
|
-
def maybe_ordinal
|
47
|
+
def maybe_ordinal(type)
|
50
48
|
@options.ordinal.result type
|
51
49
|
end
|
52
50
|
|
53
|
-
def maybe_union_after_hundreds
|
51
|
+
def maybe_union_after_hundreds(translations)
|
54
52
|
@options.hundreds_with_union.modify_or_leave translations
|
55
53
|
end
|
56
54
|
|
@@ -6,47 +6,72 @@ module NumbersAndWords
|
|
6
6
|
include Families::Latin
|
7
7
|
|
8
8
|
def capacity_iteration
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
super.compact
|
10
|
+
end
|
11
|
+
|
12
|
+
def zero
|
13
|
+
super unless maybe_remove_zero
|
14
|
+
end
|
12
15
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
end
|
19
|
-
end.compact
|
16
|
+
def ones
|
17
|
+
super({ gender: gender,
|
18
|
+
is_one_thousand: one_thousand?,
|
19
|
+
is_apocopated: one_apocopated? })
|
20
|
+
end
|
20
21
|
|
21
|
-
|
22
|
+
def tens_with_ones
|
23
|
+
if @figures.tens == 2
|
24
|
+
@translations
|
25
|
+
.twenties_with_ones(@figures, gender: gender,
|
26
|
+
is_apocopated: one_apocopated?)
|
27
|
+
else
|
28
|
+
super({ gender: gender,
|
29
|
+
is_apocopated: one_apocopated? })
|
30
|
+
end
|
22
31
|
end
|
23
32
|
|
24
33
|
def hundreds
|
25
|
-
super({
|
26
|
-
|
34
|
+
super({ gender: gender,
|
35
|
+
is_apocopated: hundred_apocopated? })
|
27
36
|
end
|
28
37
|
|
29
38
|
def megs
|
30
|
-
if
|
31
|
-
|
32
|
-
@translations.thousand
|
33
|
-
else
|
34
|
-
super({ number: @figures.number_in_capacity(@current_capacity) })
|
35
|
-
end
|
39
|
+
return @translations.megs(1, number: 1) if long_scale_thousand?
|
40
|
+
super({ number: @figures.number_in_capacity(@current_capacity) })
|
36
41
|
end
|
37
42
|
|
38
43
|
private
|
39
44
|
|
40
|
-
def
|
41
|
-
|
45
|
+
def one_thousand?
|
46
|
+
@current_capacity.odd? &&
|
47
|
+
@figures.ones == 1 &&
|
48
|
+
@figures.tens.nil? &&
|
49
|
+
@figures.hundreds.nil?
|
42
50
|
end
|
43
51
|
|
44
|
-
def
|
45
|
-
@current_capacity.odd?
|
52
|
+
def long_scale_thousand?
|
53
|
+
@current_capacity.odd? &&
|
54
|
+
@figures.number_in_capacity(@current_capacity - 1) != 0
|
55
|
+
end
|
56
|
+
|
57
|
+
def one_apocopated?
|
58
|
+
true if @current_capacity > 0 && @figures.ones == 1 ||
|
59
|
+
@options.apocopated.result
|
60
|
+
end
|
61
|
+
|
62
|
+
def hundred_apocopated?
|
63
|
+
@figures.hundreds == 1 && @figures.round_hundred?
|
64
|
+
end
|
65
|
+
|
66
|
+
def gender
|
67
|
+
@current_capacity ||= 0
|
68
|
+
|
69
|
+
return 'male'.to_sym if @current_capacity >= 2
|
70
|
+
@options.gender.result
|
46
71
|
end
|
47
72
|
|
48
|
-
def
|
49
|
-
|
73
|
+
def maybe_remove_zero
|
74
|
+
@options.remove_zero.result
|
50
75
|
end
|
51
76
|
end
|
52
77
|
end
|
@@ -13,7 +13,7 @@ module NumbersAndWords
|
|
13
13
|
number_without_capacity_to_words + complex_number_to_words
|
14
14
|
elsif @figures.hundreds
|
15
15
|
hundreds_number_to_words
|
16
|
-
elsif @figures.tens
|
16
|
+
elsif @figures.tens || @figures.ones
|
17
17
|
simple_number_to_words
|
18
18
|
else
|
19
19
|
[]
|
@@ -21,10 +21,10 @@ module NumbersAndWords
|
|
21
21
|
end
|
22
22
|
|
23
23
|
def complex_number_to_words
|
24
|
-
(1..@figures.capacity_count).map
|
24
|
+
(1..@figures.capacity_count).map do |capacity|
|
25
25
|
@current_capacity = capacity
|
26
26
|
capacity_iteration
|
27
|
-
|
27
|
+
end.flatten
|
28
28
|
end
|
29
29
|
|
30
30
|
def capacity_iteration
|
@@ -34,14 +34,14 @@ module NumbersAndWords
|
|
34
34
|
words + capacity_words
|
35
35
|
end
|
36
36
|
|
37
|
-
def words_in_capacity
|
37
|
+
def words_in_capacity(capacity = 0)
|
38
38
|
save_parent_figures do
|
39
39
|
@figures = @parent_figures.figures_array_in_capacity(capacity)
|
40
40
|
strings_logic
|
41
41
|
end
|
42
42
|
end
|
43
43
|
|
44
|
-
|
44
|
+
alias number_without_capacity_to_words words_in_capacity
|
45
45
|
|
46
46
|
def hundreds_number_to_words
|
47
47
|
simple_number_to_words + [hundreds]
|
@@ -19,14 +19,14 @@ module NumbersAndWords
|
|
19
19
|
end
|
20
20
|
end
|
21
21
|
|
22
|
-
[
|
23
|
-
define_method(method_name)
|
24
|
-
super({:gender
|
25
|
-
|
22
|
+
%i[ones tens_with_ones].each do |method_name|
|
23
|
+
define_method(method_name) do
|
24
|
+
super({ gender: gender })
|
25
|
+
end
|
26
26
|
end
|
27
27
|
|
28
28
|
def megs
|
29
|
-
super({:
|
29
|
+
super({ number: @figures.number_in_capacity(@current_capacity) })
|
30
30
|
end
|
31
31
|
end
|
32
32
|
end
|