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
93
94
95
|
# File 'lib/numbers_and_words/strategies/figures_converter/languages/vi.rb', line 93
def billion_unit
translate :mega, 3
end
|
#fraction_length ⇒ Object
72
73
74
75
76
|
# File 'lib/numbers_and_words/strategies/figures_converter/languages/vi.rb', line 72
def fraction_length
return 0 unless @options.options[:fractional]
@options.options[:fractional][:length]
end
|
#fraction_number_zeros_leading ⇒ Object
78
79
80
|
# File 'lib/numbers_and_words/strategies/figures_converter/languages/vi.rb', line 78
def fraction_number_zeros_leading
fraction_length - @figures.length
end
|
#fractional? ⇒ Boolean
68
69
70
|
# File 'lib/numbers_and_words/strategies/figures_converter/languages/vi.rb', line 68
def fractional?
!@options.options[:fractional].nil? && !@options.options[:integeral]
end
|
#fractional_with_zero_leading_string_logic ⇒ Object
26
27
28
29
|
# File 'lib/numbers_and_words/strategies/figures_converter/languages/vi.rb', line 26
def fractional_with_zero_leading_string_logic
leading_zeros = [0] * fraction_number_zeros_leading
(@figures + leading_zeros).map(&:to_words)
end
|
#hundreds(options = {}) ⇒ Object
48
49
50
51
52
53
54
|
# File 'lib/numbers_and_words/strategies/figures_converter/languages/vi.rb', line 48
def hundreds(options = {})
if @figures.hundreds.to_i.zero?
translate :hundreds, 0, options
else
super
end
end
|
#hundreds? ⇒ Boolean
43
44
45
46
|
# File 'lib/numbers_and_words/strategies/figures_converter/languages/vi.rb', line 43
def hundreds?
@figures.hundreds ||
(@figures.size == 3 && (@figures.teens || @figures.tens || @figures.ones))
end
|
#integeral_string_logic ⇒ Object
31
32
33
34
35
36
37
38
39
40
41
|
# File 'lib/numbers_and_words/strategies/figures_converter/languages/vi.rb', line 31
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
56
57
58
59
60
61
62
|
# File 'lib/numbers_and_words/strategies/figures_converter/languages/vi.rb', line 56
def ones(options = {})
if @figures.capacity_length >= 2
ones_union(options)
else
super
end
end
|
#ones_union(options = {}) ⇒ Object
64
65
66
|
# File 'lib/numbers_and_words/strategies/figures_converter/languages/vi.rb', line 64
def ones_union(options = {})
translate :ones_union, @figures.ones, options
end
|
#print_words ⇒ Object
8
9
10
11
|
# File 'lib/numbers_and_words/strategies/figures_converter/languages/vi.rb', line 8
def print_words
value = super
remove_billion_noice(value)
end
|
#remove_billion_noice(value) ⇒ Object
82
83
84
85
86
87
88
89
90
91
|
# File 'lib/numbers_and_words/strategies/figures_converter/languages/vi.rb', line 82
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
13
14
15
16
17
18
19
20
21
22
23
24
|
# File 'lib/numbers_and_words/strategies/figures_converter/languages/vi.rb', line 13
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
|