Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
305e561
commit b02f42e
Showing
7 changed files
with
132 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
coverage | ||
pkg | ||
Gemfile.lock | ||
.bundle |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 2 additions & 1 deletion
3
lib/numbers_and_words/strategies/figures_converter/options/en.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
require 'numbers_and_words/strategies/figures_converter/options/en/hundreds_with_union' | ||
require 'numbers_and_words/strategies/figures_converter/options/en/remove_hyphen' | ||
require 'numbers_and_words/strategies/figures_converter/options/en/ordinal' | ||
require 'numbers_and_words/strategies/figures_converter/options/en/remove_zero' | ||
require 'numbers_and_words/strategies/figures_converter/options/en/pronounced' | ||
require 'numbers_and_words/strategies/figures_converter/options/en/remove_zero' |
97 changes: 97 additions & 0 deletions
97
lib/numbers_and_words/strategies/figures_converter/options/en/pronounced.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
module NumbersAndWords | ||
module Strategies | ||
module FiguresConverter | ||
module Options | ||
module En | ||
class Pronounced | ||
attr_accessor :strategy, :options | ||
|
||
def initialize proxy, *args, &block | ||
@strategy = proxy.strategy | ||
@options = proxy.options | ||
end | ||
|
||
|
||
def result | ||
active? ? 'PRONOUNCED' : 'NOTPRONOUNCED' | ||
end | ||
|
||
def active? | ||
@options[:pronounced] | ||
end | ||
|
||
def process language, figures | ||
@language = language | ||
@figures = figures | ||
units, tens, hundreds, thousands = *@figures.to_a.dup | ||
|
||
if figures.to_a.count > 4 | ||
@language.number_without_capacity_to_words + @language.complex_number_to_words | ||
elsif @figures.capacity_count | ||
handle_thousands thousands, hundreds, tens, units | ||
elsif @figures.hundreds | ||
handle_hundreds hundreds, tens, units | ||
elsif @figures.tens or @figures.ones | ||
@language.simple_number_to_words | ||
else | ||
[] | ||
end | ||
end | ||
|
||
def handle_thousands thousands, hundreds, tens, units | ||
if hundreds == 0 | ||
@language.number_without_capacity_to_words + @language.complex_number_to_words | ||
else | ||
result = [] | ||
if tens == 0 && units == 0 | ||
result.push 'hundred' | ||
else | ||
result += tens_with_oh tens, units | ||
end | ||
result.push "#{thousands}#{hundreds}".to_i.to_words | ||
result | ||
end | ||
end | ||
|
||
def handle_hundreds hundreds, tens, units | ||
result = [] | ||
if tens == 0 | ||
if units == 0 | ||
result.push @language.hundreds_number_to_words | ||
else | ||
result.push @language.ones | ||
result.push 'oh' | ||
result.push hundreds.to_words | ||
end | ||
else | ||
if @figures.teens | ||
result.push @language.teens | ||
elsif @figures.tens | ||
result.push @language.complex_tens | ||
end | ||
result.push hundreds.to_words | ||
end | ||
result | ||
end | ||
|
||
def tens_with_oh tens, units | ||
result = [] | ||
if tens == 0 | ||
if units != 0 | ||
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 | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
1 change: 1 addition & 0 deletions
1
lib/numbers_and_words/strategies/figures_converter/options/en_gb.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
require 'numbers_and_words/strategies/figures_converter/options/en_gb/hundreds_with_union' | ||
require 'numbers_and_words/strategies/figures_converter/options/en_gb/remove_hyphen' | ||
require 'numbers_and_words/strategies/figures_converter/options/en_gb/ordinal' | ||
require 'numbers_and_words/strategies/figures_converter/options/en_gb/pronounced' | ||
require 'numbers_and_words/strategies/figures_converter/options/en_gb/remove_zero' |
12 changes: 12 additions & 0 deletions
12
lib/numbers_and_words/strategies/figures_converter/options/en_gb/pronounced.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
module NumbersAndWords | ||
module Strategies | ||
module FiguresConverter | ||
module Options | ||
module EnGb | ||
class Pronounced < En::Pronounced | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters