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.
- checksums.yaml +4 -4
- data/README.rdoc +10 -0
- data/lib/numbers_and_words/i18n/locales/numbers.cs.yml +37 -26
- data/lib/numbers_and_words/i18n/locales/numbers.de.yml +5 -4
- data/lib/numbers_and_words/i18n/locales/numbers.en-GB.yml +24 -8
- data/lib/numbers_and_words/i18n/locales/numbers.en.yml +10 -6
- data/lib/numbers_and_words/i18n/locales/numbers.es.yml +6 -5
- data/lib/numbers_and_words/i18n/locales/numbers.et.yml +4 -4
- data/lib/numbers_and_words/i18n/locales/numbers.fr.yml +45 -41
- data/lib/numbers_and_words/i18n/locales/numbers.hu.yml +11 -7
- data/lib/numbers_and_words/i18n/locales/numbers.it.yml +3 -3
- data/lib/numbers_and_words/i18n/locales/numbers.ka.yml +6 -14
- data/lib/numbers_and_words/i18n/locales/numbers.lt.yml +4 -5
- data/lib/numbers_and_words/i18n/locales/numbers.lv.yml +4 -5
- data/lib/numbers_and_words/i18n/locales/numbers.nl.yml +4 -3
- data/lib/numbers_and_words/i18n/locales/numbers.pt-BR.yml +51 -22
- data/lib/numbers_and_words/i18n/locales/numbers.pt.yml +21 -8
- data/lib/numbers_and_words/i18n/locales/numbers.ru.yml +39 -27
- data/lib/numbers_and_words/i18n/locales/numbers.se.yml +3 -3
- data/lib/numbers_and_words/i18n/locales/numbers.tr.yml +3 -3
- data/lib/numbers_and_words/i18n/locales/numbers.ua.yml +39 -15
- data/lib/numbers_and_words/i18n/locales/numbers.vi.yml +13 -0
- data/lib/numbers_and_words/strategies/array_joiner/languages.rb +1 -0
- data/lib/numbers_and_words/strategies/array_joiner/languages/en-GB.rb +1 -1
- data/lib/numbers_and_words/strategies/array_joiner/languages/families/base.rb +3 -3
- data/lib/numbers_and_words/strategies/array_joiner/languages/vi.rb +10 -0
- data/lib/numbers_and_words/strategies/figures_converter/decorators.rb +1 -0
- data/lib/numbers_and_words/strategies/figures_converter/decorators/hu/fractional.rb +1 -1
- data/lib/numbers_and_words/strategies/figures_converter/decorators/vi.rb +3 -0
- data/lib/numbers_and_words/strategies/figures_converter/{languages/families/latin.rb → decorators/vi/base.rb} +3 -4
- data/lib/numbers_and_words/strategies/figures_converter/decorators/vi/fractional.rb +12 -0
- data/lib/numbers_and_words/strategies/figures_converter/decorators/vi/integral.rb +12 -0
- data/lib/numbers_and_words/strategies/figures_converter/languages.rb +11 -15
- data/lib/numbers_and_words/strategies/figures_converter/languages/base.rb +2 -2
- data/lib/numbers_and_words/strategies/figures_converter/languages/cs.rb +2 -4
- data/lib/numbers_and_words/strategies/figures_converter/languages/de.rb +5 -7
- data/lib/numbers_and_words/strategies/figures_converter/languages/en.rb +0 -2
- data/lib/numbers_and_words/strategies/figures_converter/languages/es.rb +0 -2
- data/lib/numbers_and_words/strategies/figures_converter/languages/et.rb +0 -2
- data/lib/numbers_and_words/strategies/figures_converter/languages/fr.rb +10 -12
- data/lib/numbers_and_words/strategies/figures_converter/languages/hu.rb +0 -2
- data/lib/numbers_and_words/strategies/figures_converter/languages/it.rb +0 -1
- data/lib/numbers_and_words/strategies/figures_converter/languages/ka.rb +10 -12
- data/lib/numbers_and_words/strategies/figures_converter/languages/lt.rb +6 -12
- data/lib/numbers_and_words/strategies/figures_converter/languages/lv.rb +2 -14
- data/lib/numbers_and_words/strategies/figures_converter/languages/nl.rb +0 -2
- data/lib/numbers_and_words/strategies/figures_converter/languages/pt-BR.rb +1 -3
- data/lib/numbers_and_words/strategies/figures_converter/languages/pt.rb +1 -3
- data/lib/numbers_and_words/strategies/figures_converter/languages/se.rb +0 -1
- data/lib/numbers_and_words/strategies/figures_converter/languages/tr.rb +2 -4
- data/lib/numbers_and_words/strategies/figures_converter/languages/vi.rb +96 -0
- data/lib/numbers_and_words/translations.rb +1 -0
- data/lib/numbers_and_words/translations/cs.rb +4 -31
- data/lib/numbers_and_words/translations/de.rb +3 -3
- data/lib/numbers_and_words/translations/en-GB.rb +3 -1
- data/lib/numbers_and_words/translations/es.rb +5 -20
- data/lib/numbers_and_words/translations/et.rb +2 -7
- data/lib/numbers_and_words/translations/extensions/fraction_significance.rb +4 -4
- data/lib/numbers_and_words/translations/families/base.rb +3 -3
- data/lib/numbers_and_words/translations/families/cyrillic.rb +4 -8
- data/lib/numbers_and_words/translations/fr.rb +9 -14
- data/lib/numbers_and_words/translations/hu.rb +2 -7
- data/lib/numbers_and_words/translations/ka.rb +3 -13
- data/lib/numbers_and_words/translations/lt.rb +2 -11
- data/lib/numbers_and_words/translations/lv.rb +2 -11
- data/lib/numbers_and_words/translations/nl.rb +3 -2
- data/lib/numbers_and_words/translations/pt-BR.rb +14 -21
- data/lib/numbers_and_words/translations/pt.rb +3 -12
- data/lib/numbers_and_words/translations/ru.rb +0 -17
- data/lib/numbers_and_words/translations/tr.rb +0 -4
- data/lib/numbers_and_words/translations/ua.rb +0 -13
- data/lib/numbers_and_words/translations/vi.rb +21 -0
- data/lib/numbers_and_words/version.rb +1 -1
- metadata +11 -4
@@ -1,33 +1,29 @@
|
|
1
1
|
require 'numbers_and_words/strategies/figures_converter/languages/families/helpers'
|
2
2
|
require 'numbers_and_words/strategies/figures_converter/languages/families/base'
|
3
|
-
|
4
3
|
require 'numbers_and_words/strategies/figures_converter/languages/base'
|
5
4
|
|
6
|
-
require 'numbers_and_words/strategies/figures_converter/languages/
|
7
|
-
|
5
|
+
require 'numbers_and_words/strategies/figures_converter/languages/cs'
|
6
|
+
require 'numbers_and_words/strategies/figures_converter/languages/de'
|
8
7
|
require 'numbers_and_words/strategies/figures_converter/languages/en'
|
9
8
|
require 'numbers_and_words/strategies/figures_converter/languages/en-GB'
|
9
|
+
require 'numbers_and_words/strategies/figures_converter/languages/es'
|
10
|
+
require 'numbers_and_words/strategies/figures_converter/languages/et'
|
10
11
|
require 'numbers_and_words/strategies/figures_converter/languages/fr'
|
11
12
|
require 'numbers_and_words/strategies/figures_converter/languages/hu'
|
12
|
-
require 'numbers_and_words/strategies/figures_converter/languages/et'
|
13
|
-
require 'numbers_and_words/strategies/figures_converter/languages/se'
|
14
13
|
require 'numbers_and_words/strategies/figures_converter/languages/it'
|
14
|
+
require 'numbers_and_words/strategies/figures_converter/languages/ka'
|
15
|
+
require 'numbers_and_words/strategies/figures_converter/languages/lt'
|
16
|
+
require 'numbers_and_words/strategies/figures_converter/languages/lv'
|
15
17
|
require 'numbers_and_words/strategies/figures_converter/languages/nl'
|
18
|
+
require 'numbers_and_words/strategies/figures_converter/languages/pt-BR'
|
19
|
+
require 'numbers_and_words/strategies/figures_converter/languages/pt'
|
20
|
+
require 'numbers_and_words/strategies/figures_converter/languages/se'
|
16
21
|
require 'numbers_and_words/strategies/figures_converter/languages/tr'
|
17
|
-
require 'numbers_and_words/strategies/figures_converter/languages/es'
|
18
|
-
require 'numbers_and_words/strategies/figures_converter/languages/lv'
|
19
|
-
require 'numbers_and_words/strategies/figures_converter/languages/lt'
|
20
|
-
require 'numbers_and_words/strategies/figures_converter/languages/de'
|
21
22
|
|
22
23
|
require 'numbers_and_words/strategies/figures_converter/languages/families/cyrillic'
|
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/
|
27
|
-
require 'numbers_and_words/strategies/figures_converter/languages/pt-BR'
|
28
|
-
require 'numbers_and_words/strategies/figures_converter/languages/cs'
|
29
|
-
|
30
|
-
require 'numbers_and_words/strategies/figures_converter/languages/ka'
|
26
|
+
require 'numbers_and_words/strategies/figures_converter/languages/vi'
|
31
27
|
|
32
28
|
module NumbersAndWords
|
33
29
|
module Strategies
|
@@ -3,7 +3,7 @@ module NumbersAndWords
|
|
3
3
|
module FiguresConverter
|
4
4
|
module Languages
|
5
5
|
class Base
|
6
|
-
include
|
6
|
+
include Families::Base
|
7
7
|
|
8
8
|
attr_accessor :strategy, :figures, :translations, :strings, :options
|
9
9
|
|
@@ -20,7 +20,7 @@ module NumbersAndWords
|
|
20
20
|
end
|
21
21
|
|
22
22
|
def print_words
|
23
|
-
@strings.reverse.join
|
23
|
+
@strings.reverse.join(' ')
|
24
24
|
end
|
25
25
|
end
|
26
26
|
end
|
@@ -3,8 +3,6 @@ module NumbersAndWords
|
|
3
3
|
module FiguresConverter
|
4
4
|
module Languages
|
5
5
|
class Cs < Base
|
6
|
-
include Families::Latin
|
7
|
-
|
8
6
|
# methods in translations/cs.rb which can work with :gender or :ordinal
|
9
7
|
%i[ones teens tens tens_with_ones hundreds].each do |method_name|
|
10
8
|
define_method(method_name) do
|
@@ -21,13 +19,13 @@ module NumbersAndWords
|
|
21
19
|
end
|
22
20
|
|
23
21
|
def gender
|
24
|
-
@current_capacity ||= 0
|
25
22
|
# @current_capacity = order of block of 3 digits, backwards (0 = hundreds tens ones)
|
23
|
+
@current_capacity ||= 0
|
26
24
|
|
27
25
|
if @current_capacity.zero?
|
28
26
|
options.gender.result
|
29
27
|
elsif @current_capacity > 2 && @current_capacity.odd?
|
30
|
-
:female # miliardy, biliardy, triliardy
|
28
|
+
:female # miliardy, biliardy, triliardy...
|
31
29
|
else
|
32
30
|
:male
|
33
31
|
end
|
@@ -3,14 +3,12 @@ module NumbersAndWords
|
|
3
3
|
module FiguresConverter
|
4
4
|
module Languages
|
5
5
|
class De < Base
|
6
|
-
include Families::Latin
|
7
|
-
|
8
6
|
def print_words
|
9
|
-
complex_part.count > 1 ? print_megs_words : @strings.flatten.reverse.join
|
7
|
+
complex_part.count > 1 ? print_megs_words : @strings.flatten.reverse.join
|
10
8
|
end
|
11
9
|
|
12
10
|
def print_megs_words
|
13
|
-
[print_megs, print_other].reject(&:empty?).join
|
11
|
+
[print_megs, print_other].reject(&:empty?).join(' ')
|
14
12
|
end
|
15
13
|
|
16
14
|
def complex_number_to_words
|
@@ -40,16 +38,16 @@ module NumbersAndWords
|
|
40
38
|
|
41
39
|
def print_megs
|
42
40
|
complex_part[1..-1].map do |el|
|
43
|
-
[el[1..-1].to_a.reverse.join
|
41
|
+
[el[1..-1].to_a.reverse.join, el.first].join(' ')
|
44
42
|
end.reject(&:empty?).reverse.join(' ')
|
45
43
|
end
|
46
44
|
|
47
45
|
def print_other
|
48
|
-
[print_thousands, simple_part.reverse.join
|
46
|
+
[print_thousands, simple_part.reverse.join].join
|
49
47
|
end
|
50
48
|
|
51
49
|
def print_thousands
|
52
|
-
complex_part.first.reverse.join
|
50
|
+
complex_part.first.reverse.join
|
53
51
|
end
|
54
52
|
|
55
53
|
def simple_part
|
@@ -3,10 +3,6 @@ module NumbersAndWords
|
|
3
3
|
module FiguresConverter
|
4
4
|
module Languages
|
5
5
|
class Fr < Base
|
6
|
-
include Families::Latin
|
7
|
-
|
8
|
-
private
|
9
|
-
|
10
6
|
def capacity_iteration
|
11
7
|
words = []
|
12
8
|
capacity_words = words_in_capacity(@current_capacity)
|
@@ -15,14 +11,6 @@ module NumbersAndWords
|
|
15
11
|
words
|
16
12
|
end
|
17
13
|
|
18
|
-
def one?
|
19
|
-
words_in_capacity(@current_capacity) == [translations.ones(1)]
|
20
|
-
end
|
21
|
-
|
22
|
-
def thousand?
|
23
|
-
FiguresArray::THOUSAND_CAPACITY == @current_capacity
|
24
|
-
end
|
25
|
-
|
26
14
|
def hundreds
|
27
15
|
super({ pluralize: simple_number_to_words.empty? })
|
28
16
|
end
|
@@ -30,6 +18,16 @@ module NumbersAndWords
|
|
30
18
|
def megs
|
31
19
|
super({ number: @figures.number_in_capacity(@current_capacity) })
|
32
20
|
end
|
21
|
+
|
22
|
+
private
|
23
|
+
|
24
|
+
def one?
|
25
|
+
words_in_capacity(@current_capacity) == [translations.ones(1)]
|
26
|
+
end
|
27
|
+
|
28
|
+
def thousand?
|
29
|
+
FiguresArray::THOUSAND_CAPACITY == @current_capacity
|
30
|
+
end
|
33
31
|
end
|
34
32
|
end
|
35
33
|
end
|
@@ -3,10 +3,6 @@ module NumbersAndWords
|
|
3
3
|
module FiguresConverter
|
4
4
|
module Languages
|
5
5
|
class Ka < Base
|
6
|
-
include Families::Latin
|
7
|
-
|
8
|
-
private
|
9
|
-
|
10
6
|
def capacity_iteration
|
11
7
|
words = []
|
12
8
|
capacity_words = words_in_capacity(@current_capacity)
|
@@ -15,14 +11,6 @@ module NumbersAndWords
|
|
15
11
|
words
|
16
12
|
end
|
17
13
|
|
18
|
-
def one?
|
19
|
-
words_in_capacity(@current_capacity) == [translations.ones(1)]
|
20
|
-
end
|
21
|
-
|
22
|
-
def thousand?
|
23
|
-
FiguresArray::THOUSAND_CAPACITY == @current_capacity
|
24
|
-
end
|
25
|
-
|
26
14
|
def hundreds
|
27
15
|
super({ only_hundreds: figures[0, 2] == [0, 0] })
|
28
16
|
end
|
@@ -34,6 +22,16 @@ module NumbersAndWords
|
|
34
22
|
|
35
23
|
super(prefix: prefix)
|
36
24
|
end
|
25
|
+
|
26
|
+
private
|
27
|
+
|
28
|
+
def one?
|
29
|
+
words_in_capacity(@current_capacity) == [translations.ones(1)]
|
30
|
+
end
|
31
|
+
|
32
|
+
def thousand?
|
33
|
+
FiguresArray::THOUSAND_CAPACITY == @current_capacity
|
34
|
+
end
|
37
35
|
end
|
38
36
|
end
|
39
37
|
end
|
@@ -3,10 +3,6 @@ module NumbersAndWords
|
|
3
3
|
module FiguresConverter
|
4
4
|
module Languages
|
5
5
|
class Lt < Base
|
6
|
-
include Families::Latin
|
7
|
-
|
8
|
-
private
|
9
|
-
|
10
6
|
def capacity_iteration
|
11
7
|
words = []
|
12
8
|
capacity_words = words_in_capacity(@current_capacity)
|
@@ -15,6 +11,12 @@ module NumbersAndWords
|
|
15
11
|
words
|
16
12
|
end
|
17
13
|
|
14
|
+
def megs
|
15
|
+
super({ number: @figures.number_in_capacity(@current_capacity) })
|
16
|
+
end
|
17
|
+
|
18
|
+
private
|
19
|
+
|
18
20
|
def one?
|
19
21
|
words_in_capacity(@current_capacity) == [translations.ones(1)]
|
20
22
|
end
|
@@ -22,14 +24,6 @@ module NumbersAndWords
|
|
22
24
|
def thousand?
|
23
25
|
FiguresArray::THOUSAND_CAPACITY == @current_capacity
|
24
26
|
end
|
25
|
-
|
26
|
-
def hundreds
|
27
|
-
super({ is_hundred: (figures[1, 2] == [0, 1] && simple_number_to_words.empty?) })
|
28
|
-
end
|
29
|
-
|
30
|
-
def megs
|
31
|
-
super({ number: @figures.number_in_capacity(@current_capacity) })
|
32
|
-
end
|
33
27
|
end
|
34
28
|
end
|
35
29
|
end
|
@@ -3,20 +3,8 @@ module NumbersAndWords
|
|
3
3
|
module FiguresConverter
|
4
4
|
module Languages
|
5
5
|
class Lv < Base
|
6
|
-
|
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
|
15
|
-
words
|
16
|
-
end
|
17
|
-
|
18
|
-
def hundreds
|
19
|
-
super({ is_hundred: (figures[1, 2] == [0, 1] && simple_number_to_words.empty?) })
|
6
|
+
def tens_with_ones
|
7
|
+
super separator: ' '
|
20
8
|
end
|
21
9
|
|
22
10
|
def megs
|
@@ -3,8 +3,6 @@ module NumbersAndWords
|
|
3
3
|
module FiguresConverter
|
4
4
|
module Languages
|
5
5
|
class PtBr < Base
|
6
|
-
include Families::Latin
|
7
|
-
|
8
6
|
%i[teens tens tens_with_ones].each do |method_name|
|
9
7
|
define_method(method_name) do
|
10
8
|
super(internal_options)
|
@@ -39,7 +37,7 @@ module NumbersAndWords
|
|
39
37
|
end
|
40
38
|
|
41
39
|
def megs
|
42
|
-
super(internal_options.merge(
|
40
|
+
super(internal_options.merge(number: @figures.number_in_capacity(@current_capacity),
|
43
41
|
is_opaque: opaque?,
|
44
42
|
is_without_connector: without_connector?,
|
45
43
|
is_with_comma: with_comma?))
|
@@ -3,14 +3,12 @@ module NumbersAndWords
|
|
3
3
|
module FiguresConverter
|
4
4
|
module Languages
|
5
5
|
class Pt < Base
|
6
|
-
include Families::Latin
|
7
|
-
|
8
6
|
def hundreds
|
9
7
|
super({ is_hundred: hundred?, is_one_hundred: one_hundred? })
|
10
8
|
end
|
11
9
|
|
12
10
|
def megs
|
13
|
-
super({
|
11
|
+
super({ number: @figures.number_in_capacity(@current_capacity) })
|
14
12
|
end
|
15
13
|
|
16
14
|
private
|
@@ -3,10 +3,6 @@ module NumbersAndWords
|
|
3
3
|
module FiguresConverter
|
4
4
|
module Languages
|
5
5
|
class Tr < Base
|
6
|
-
include Families::Latin
|
7
|
-
|
8
|
-
private
|
9
|
-
|
10
6
|
def capacity_iteration
|
11
7
|
words = []
|
12
8
|
capacity_words = words_in_capacity(@current_capacity)
|
@@ -15,6 +11,8 @@ module NumbersAndWords
|
|
15
11
|
words
|
16
12
|
end
|
17
13
|
|
14
|
+
private
|
15
|
+
|
18
16
|
def one?
|
19
17
|
words_in_capacity(@current_capacity) == [translations.ones(1)]
|
20
18
|
end
|
@@ -0,0 +1,96 @@
|
|
1
|
+
module NumbersAndWords
|
2
|
+
module Strategies
|
3
|
+
module FiguresConverter
|
4
|
+
module Languages
|
5
|
+
class Vi < Base
|
6
|
+
def print_words
|
7
|
+
value = super
|
8
|
+
remove_billion_noice(value)
|
9
|
+
end
|
10
|
+
|
11
|
+
def strings_logic
|
12
|
+
if fractional?
|
13
|
+
if fraction_number_zeros_leading.zero?
|
14
|
+
@options.options[:integeral] = true
|
15
|
+
integeral_string_logic
|
16
|
+
else
|
17
|
+
fractional_with_zero_leading_string_logic
|
18
|
+
end
|
19
|
+
else
|
20
|
+
integeral_string_logic
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def fractional_with_zero_leading_string_logic
|
25
|
+
leading_zeros = [0] * fraction_number_zeros_leading
|
26
|
+
(@figures + leading_zeros).map(&:to_words)
|
27
|
+
end
|
28
|
+
|
29
|
+
def integeral_string_logic
|
30
|
+
if @figures.capacity_count
|
31
|
+
number_without_capacity_to_words + complex_number_to_words
|
32
|
+
elsif hundreds?
|
33
|
+
hundreds_number_to_words
|
34
|
+
elsif @figures.tens || @figures.ones
|
35
|
+
simple_number_to_words
|
36
|
+
else
|
37
|
+
[]
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
def hundreds?
|
42
|
+
@figures.hundreds ||
|
43
|
+
(@figures.size == 3 && (@figures.teens || @figures.tens || @figures.ones))
|
44
|
+
end
|
45
|
+
|
46
|
+
def hundreds(options = {})
|
47
|
+
if @figures.hundreds.to_i.zero?
|
48
|
+
translate :hundreds, 0, options
|
49
|
+
else
|
50
|
+
super
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
def ones(options = {})
|
55
|
+
if @figures.capacity_length >= 2
|
56
|
+
ones_union(options)
|
57
|
+
else
|
58
|
+
super
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
def ones_union(options = {})
|
63
|
+
translate :ones_union, @figures.ones, options
|
64
|
+
end
|
65
|
+
|
66
|
+
def fractional?
|
67
|
+
!@options.options[:fractional].nil? && !@options.options[:integeral]
|
68
|
+
end
|
69
|
+
|
70
|
+
def fraction_length
|
71
|
+
return 0 unless @options.options[:fractional]
|
72
|
+
@options.options[:fractional][:length]
|
73
|
+
end
|
74
|
+
|
75
|
+
def fraction_number_zeros_leading
|
76
|
+
fraction_length - @figures.length
|
77
|
+
end
|
78
|
+
|
79
|
+
def remove_billion_noice(value)
|
80
|
+
parts = value.split(billion_unit).map(&:strip)
|
81
|
+
if value.end_with?(billion_unit)
|
82
|
+
parts.insert(-1, billion_unit).join(' ')
|
83
|
+
else
|
84
|
+
return value if parts.size <= 2
|
85
|
+
parts.insert(-2, billion_unit).join(' ')
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
def billion_unit
|
90
|
+
translate :mega, 3
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|