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
Showing
41 changed files
with
534 additions
and
34 deletions.
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
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
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,6 +1,6 @@ | ||
class Array | ||
def to_words options = {} | ||
map &:to_words | ||
map{|element| element.to_words options} | ||
end | ||
|
||
def to_figures | ||
|
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,55 @@ | ||
en-GB: | ||
numbers: | ||
ones: [zero, one, two, three, four, five, six, seven, eight, nine] | ||
teens: [ten, eleven, twelve, thirteen, fourteen, fifteen, sixteen, seventeen, eighteen, nineteen] | ||
tens: [zero, ten, twenty, thirty, forty, fifty, sixty, seventy, eighty, ninety] | ||
hundreds: hundred | ||
mega: [ones, thousand, million, billion, trillion, quadrillion, quintillion, sextillion, septillion, octillion, nonillion, decillion] | ||
ordinal: | ||
ones: [zeroth, first, second, third, fourth, fifth, sixth, seventh, eighth, ninth] | ||
teens: [tenth, eleventh, twelfth, thirteenth, fourteenth, fifteenth, sixteenth, seventeenth, eighteenth, nineteenth] | ||
tens: [zeroth, tenth, twentieth, thirtieth, fortieth, fiftieth, sixtieth, seventieth, eightieth, ninetieth] | ||
hundreds: hundredth | ||
mega: [zeroth, thousandth, millionth, billionth, trillionth, quadrillionth, quintillionth, sextillionth, septillionth, octillionth, nonillionth, decillionth] | ||
fraction_separator: and | ||
micro: [_, tenths, hundredths, thousandths, millionths, billionths, trillionths, quadrillionths, quintillionths, sextillionths, septillionths, octillionths, nonillionths, decillionths] | ||
tenths: | ||
one: tenth | ||
other: tenths | ||
hundredths: | ||
one: hundredth | ||
other: hundredths | ||
thousandths: | ||
one: thousandth | ||
other: thousandths | ||
millionths: | ||
one: millionth | ||
other: millionths | ||
billionths: | ||
one: billionth | ||
other: billionths | ||
trillionths: | ||
one: trillionth | ||
other: trillionths | ||
quadrillionths: | ||
one: quadrillionth | ||
other: quadrillionths | ||
quintillionths: | ||
one: quintillionth | ||
other: quintillionths | ||
sextillionths: | ||
one: sextillionth | ||
other: sextillionths | ||
septillionths: | ||
one: septillionth | ||
other: septillionths | ||
octillionths: | ||
one: octillionth | ||
other: octillionths | ||
nonillionths: | ||
one: nonillionth | ||
other: nonillionths | ||
decillionths: | ||
one: decillionth | ||
other: decillionths | ||
union: point |
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
27 changes: 27 additions & 0 deletions
27
lib/numbers_and_words/strategies/array_joiner/languages.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,27 @@ | ||
require 'numbers_and_words/strategies/array_joiner/languages/families/base' | ||
|
||
require 'numbers_and_words/strategies/array_joiner/languages/base' | ||
|
||
require 'numbers_and_words/strategies/array_joiner/languages/en' | ||
require 'numbers_and_words/strategies/array_joiner/languages/en_gb' | ||
require 'numbers_and_words/strategies/array_joiner/languages/hu' | ||
require 'numbers_and_words/strategies/array_joiner/languages/ru' | ||
require 'numbers_and_words/strategies/array_joiner/languages/ua' | ||
|
||
module NumbersAndWords | ||
module Strategies | ||
module ArrayJoiner | ||
module Languages | ||
class << self | ||
def factory strategy | ||
"#{name}::#{language_class_name}".constantize.new strategy | ||
end | ||
|
||
def language_class_name | ||
::I18n.locale.to_s.titleize.gsub ' ', '' | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
24 changes: 24 additions & 0 deletions
24
lib/numbers_and_words/strategies/array_joiner/languages/base.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,24 @@ | ||
module NumbersAndWords | ||
module Strategies | ||
module ArrayJoiner | ||
module Languages | ||
class Base | ||
include Languages::Families::Base | ||
|
||
attr_accessor :strategy, :elements, :translations, :strings, :options | ||
|
||
def initialize strategy | ||
@strategy = strategy | ||
@elements = strategy.elements | ||
@translations = strategy.translations | ||
@options = strategy.options | ||
end | ||
|
||
def join | ||
elements_logic | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
10 changes: 10 additions & 0 deletions
10
lib/numbers_and_words/strategies/array_joiner/languages/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 |
---|---|---|
@@ -0,0 +1,10 @@ | ||
module NumbersAndWords | ||
module Strategies | ||
module ArrayJoiner | ||
module Languages | ||
class En < Base | ||
end | ||
end | ||
end | ||
end | ||
end |
17 changes: 17 additions & 0 deletions
17
lib/numbers_and_words/strategies/array_joiner/languages/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 |
---|---|---|
@@ -0,0 +1,17 @@ | ||
module NumbersAndWords | ||
module Strategies | ||
module ArrayJoiner | ||
module Languages | ||
class EnGb < Base | ||
def elements_logic | ||
@elements.join union_element | ||
end | ||
|
||
def union_element | ||
@elements.first.blank? ? "#{union_separator} " : super | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
24 changes: 24 additions & 0 deletions
24
lib/numbers_and_words/strategies/array_joiner/languages/families/base.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,24 @@ | ||
module NumbersAndWords | ||
module Strategies | ||
module ArrayJoiner | ||
module Languages | ||
module Families | ||
module Base | ||
|
||
def elements_logic | ||
@elements.first.blank? ? @elements.last : @elements.join(union_element) | ||
end | ||
|
||
def union_element | ||
union_separator.present? ? " #{union_separator} " : ' ' | ||
end | ||
|
||
def union_separator | ||
options[:union_separator] || @translations.union || '' | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
10 changes: 10 additions & 0 deletions
10
lib/numbers_and_words/strategies/array_joiner/languages/hu.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,10 @@ | ||
module NumbersAndWords | ||
module Strategies | ||
module ArrayJoiner | ||
module Languages | ||
class Hu < Base | ||
end | ||
end | ||
end | ||
end | ||
end |
10 changes: 10 additions & 0 deletions
10
lib/numbers_and_words/strategies/array_joiner/languages/ru.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,10 @@ | ||
module NumbersAndWords | ||
module Strategies | ||
module ArrayJoiner | ||
module Languages | ||
class Ru < Base | ||
end | ||
end | ||
end | ||
end | ||
end |
10 changes: 10 additions & 0 deletions
10
lib/numbers_and_words/strategies/array_joiner/languages/ua.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,10 @@ | ||
module NumbersAndWords | ||
module Strategies | ||
module ArrayJoiner | ||
module Languages | ||
class Ua < Base | ||
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
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: 3 additions & 0 deletions
3
lib/numbers_and_words/strategies/figures_converter/decorators/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 |
---|---|---|
@@ -0,0 +1,3 @@ | ||
require 'numbers_and_words/strategies/figures_converter/decorators/en_gb/base' | ||
require 'numbers_and_words/strategies/figures_converter/decorators/en_gb/fractional' | ||
require 'numbers_and_words/strategies/figures_converter/decorators/en_gb/integral' |
12 changes: 12 additions & 0 deletions
12
lib/numbers_and_words/strategies/figures_converter/decorators/en_gb/base.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 Decorators | ||
module EnGb | ||
class Base < En::Base | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
27 changes: 27 additions & 0 deletions
27
lib/numbers_and_words/strategies/figures_converter/decorators/en_gb/fractional.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,27 @@ | ||
module NumbersAndWords | ||
module Strategies | ||
module FiguresConverter | ||
module Decorators | ||
module EnGb | ||
class Fractional < En::Fractional | ||
SHIFT_ZERO_LENGTH = 1 | ||
|
||
def run | ||
fraction_to_digits | ||
end | ||
|
||
private | ||
|
||
def fraction_to_digits | ||
full_fraction.to_a.to_words.join ' ' | ||
end | ||
|
||
def zero_length | ||
super - SHIFT_ZERO_LENGTH | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
12 changes: 12 additions & 0 deletions
12
lib/numbers_and_words/strategies/figures_converter/decorators/en_gb/integral.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 Decorators | ||
module EnGb | ||
class Integral < En::Integral | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
Oops, something went wrong.