Class: NumbersAndWords::Strategies::FiguresConverter::Options::En::Pronounced
- Inherits:
-
Object
- Object
- NumbersAndWords::Strategies::FiguresConverter::Options::En::Pronounced
show all
- Defined in:
- lib/numbers_and_words/strategies/figures_converter/options/en/pronounced.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(proxy, *args, &block) ⇒ Pronounced
Returns a new instance of Pronounced.
9
10
11
12
|
# File 'lib/numbers_and_words/strategies/figures_converter/options/en/pronounced.rb', line 9
def initialize proxy, *args, &block
@strategy = proxy.strategy
@options = proxy.options
end
|
Instance Attribute Details
#options ⇒ Object
Returns the value of attribute options.
7
8
9
|
# File 'lib/numbers_and_words/strategies/figures_converter/options/en/pronounced.rb', line 7
def options
@options
end
|
#strategy ⇒ Object
Returns the value of attribute strategy.
7
8
9
|
# File 'lib/numbers_and_words/strategies/figures_converter/options/en/pronounced.rb', line 7
def strategy
@strategy
end
|
Instance Method Details
#active? ⇒ Boolean
19
20
21
|
# File 'lib/numbers_and_words/strategies/figures_converter/options/en/pronounced.rb', line 19
def active?
@options[:pronounced]
end
|
#handle_hundreds(language, figures) ⇒ Object
47
48
49
50
51
|
# File 'lib/numbers_and_words/strategies/figures_converter/options/en/pronounced.rb', line 47
def handle_hundreds language, figures
units, tens, hundreds = *figures.to_a.dup
result = tens_with_oh language, figures
result.push hundreds.to_words
end
|
#handle_thousands(language, figures) ⇒ Object
37
38
39
40
41
42
43
44
45
|
# File 'lib/numbers_and_words/strategies/figures_converter/options/en/pronounced.rb', line 37
def handle_thousands language, figures
units, tens, hundreds, thousands = *figures.to_a.dup
if hundreds == 0
language.number_without_capacity_to_words + language.complex_number_to_words
else
result = tens_with_oh language, figures
result.push "#{thousands}#{hundreds}".to_i.to_words
end
end
|
#process(language, figures) ⇒ Object
23
24
25
26
27
28
29
30
31
32
33
34
35
|
# File 'lib/numbers_and_words/strategies/figures_converter/options/en/pronounced.rb', line 23
def process language, figures
if figures.to_a.count > 4
language.number_without_capacity_to_words + language.complex_number_to_words
elsif figures.capacity_count
handle_thousands language, figures
elsif figures.hundreds
handle_hundreds language, figures
elsif figures.tens or figures.ones
language.simple_number_to_words
else
[]
end
end
|
#result ⇒ Object
15
16
17
|
# File 'lib/numbers_and_words/strategies/figures_converter/options/en/pronounced.rb', line 15
def result
active? ? 'PRONOUNCED' : 'NOTPRONOUNCED'
end
|
#tens_with_oh(language, figures) ⇒ Object
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
|
# File 'lib/numbers_and_words/strategies/figures_converter/options/en/pronounced.rb', line 53
def tens_with_oh language, figures
units, tens = *figures.to_a.dup
result = []
if tens == 0
if units == 0
result.push 'hundred'
else
result.push language.ones
result.push 'oh'
end
else
if figures.teens
result.push language.teens
elsif figures.tens
result.push language.complex_tens
end
end
end
|