Class: NumbersAndWords::Strategies::FiguresConverter::Languages::Vi
- Inherits:
-
Base
- Object
- Base
- NumbersAndWords::Strategies::FiguresConverter::Languages::Vi
show all
- Defined in:
- lib/numbers_and_words/strategies/figures_converter/languages/vi.rb
Instance Attribute Summary
Attributes inherited from Base
#decorator, #figures, #language, #options, #translations
Instance Method Summary
collapse
Methods inherited from Base
#initialize, #run
Instance Method Details
#billion_unit ⇒ Object
89
90
91
|
# File 'lib/numbers_and_words/strategies/figures_converter/languages/vi.rb', line 89
def billion_unit
translate :mega, 3
end
|
#fraction_length ⇒ Object
70
71
72
73
|
# File 'lib/numbers_and_words/strategies/figures_converter/languages/vi.rb', line 70
def fraction_length
return 0 unless @options.options[:fractional]
@options.options[:fractional][:length]
end
|
#fraction_number_zeros_leading ⇒ Object
75
76
77
|
# File 'lib/numbers_and_words/strategies/figures_converter/languages/vi.rb', line 75
def fraction_number_zeros_leading
fraction_length - @figures.length
end
|
#fractional? ⇒ Boolean
66
67
68
|
# File 'lib/numbers_and_words/strategies/figures_converter/languages/vi.rb', line 66
def fractional?
!@options.options[:fractional].nil? && !@options.options[:integeral]
end
|
#fractional_with_zero_leading_string_logic ⇒ Object
24
25
26
27
|
# File 'lib/numbers_and_words/strategies/figures_converter/languages/vi.rb', line 24
def fractional_with_zero_leading_string_logic
leading_zeros = [0] * fraction_number_zeros_leading
(@figures + leading_zeros).map(&:to_words)
end
|
#hundreds(options = {}) ⇒ Object
46
47
48
49
50
51
52
|
# File 'lib/numbers_and_words/strategies/figures_converter/languages/vi.rb', line 46
def hundreds(options = {})
if @figures.hundreds.to_i.zero?
translate :hundreds, 0, options
else
super
end
end
|
#hundreds? ⇒ Boolean
41
42
43
44
|
# File 'lib/numbers_and_words/strategies/figures_converter/languages/vi.rb', line 41
def hundreds?
@figures.hundreds ||
(@figures.size == 3 && (@figures.teens || @figures.tens || @figures.ones))
end
|
#integeral_string_logic ⇒ Object
29
30
31
32
33
34
35
36
37
38
39
|
# File 'lib/numbers_and_words/strategies/figures_converter/languages/vi.rb', line 29
def integeral_string_logic
if @figures.capacity_count
number_without_capacity_to_words + complex_number_to_words
elsif hundreds?
hundreds_number_to_words
elsif @figures.tens || @figures.ones
simple_number_to_words
else
[]
end
end
|
#ones(options = {}) ⇒ Object
54
55
56
57
58
59
60
|
# File 'lib/numbers_and_words/strategies/figures_converter/languages/vi.rb', line 54
def ones(options = {})
if @figures.capacity_length >= 2
ones_union(options)
else
super
end
end
|
#ones_union(options = {}) ⇒ Object
62
63
64
|
# File 'lib/numbers_and_words/strategies/figures_converter/languages/vi.rb', line 62
def ones_union(options = {})
translate :ones_union, @figures.ones, options
end
|
#print_words ⇒ Object
6
7
8
9
|
# File 'lib/numbers_and_words/strategies/figures_converter/languages/vi.rb', line 6
def print_words
value = super
remove_billion_noice(value)
end
|
#remove_billion_noice(value) ⇒ Object
79
80
81
82
83
84
85
86
87
|
# File 'lib/numbers_and_words/strategies/figures_converter/languages/vi.rb', line 79
def remove_billion_noice(value)
parts = value.split(billion_unit).map(&:strip)
if value.end_with?(billion_unit)
parts.insert(-1, billion_unit).join(' ')
else
return value if parts.size <= 2
parts.insert(-2, billion_unit).join(' ')
end
end
|
#strings_logic ⇒ Object
11
12
13
14
15
16
17
18
19
20
21
22
|
# File 'lib/numbers_and_words/strategies/figures_converter/languages/vi.rb', line 11
def strings_logic
if fractional?
if fraction_number_zeros_leading.zero?
@options.options[:integeral] = true
integeral_string_logic
else
fractional_with_zero_leading_string_logic
end
else
integeral_string_logic
end
end
|