Skip to content

Commit

Permalink
Merge branch 'release/0.7.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
kslazarev committed Apr 14, 2013
2 parents 9e9212c + f644169 commit 58bc280
Show file tree
Hide file tree
Showing 41 changed files with 534 additions and 34 deletions.
8 changes: 7 additions & 1 deletion CHANGELOG.md
@@ -1,4 +1,10 @@
## 0.6.1
## 0.7.0 (April 14, 2013)

### Features
* Send number's options through array. \[[#60](https://github.com/kslazarev/numbers_and_words/issues/60)\] \([@kslazarev](https://github.com/kslazarev)\)
* Add British English. \[[#57](https://github.com/kslazarev/numbers_and_words/issues/57)\] \([@eLod](https://github.com/eLod)\)

## 0.6.1 (April 11, 2013)

### Bugs
* Extra 'and' added after round hundreds (using hundreds_with_union: true) in English. \[[#58](https://github.com/kslazarev/numbers_and_words/issues/58)\] \([@eLod](https://github.com/eLod)\)
Expand Down
9 changes: 7 additions & 2 deletions README.rdoc
Expand Up @@ -4,7 +4,7 @@
{<img src="https://gemnasium.com/kslazarev/numbers_and_words.png" alt="Dependency Status" />}[https://gemnasium.com/kslazarev/numbers_and_words]
{<img src="https://codeclimate.com/github/kslazarev/numbers_and_words.png" />}[https://codeclimate.com/github/kslazarev/numbers_and_words]
{<img src="https://secure.travis-ci.org/kslazarev/numbers_and_words.png" />}[http://travis-ci.org/kslazarev/numbers_and_words]
{<img src="https://coveralls.io/repos/kslazarev/numbers_and_words/badge.png?branch=development" alt="Coverage Status" />}[https://coveralls.io/r/kslazarev/numbers_and_words]
{<img src="https://coveralls.io/repos/kslazarev/numbers_and_words/badge.png" alt="Coverage Status" />}[https://coveralls.io/r/kslazarev/numbers_and_words]

Convert numbers to words using the I18n library.

Expand All @@ -26,6 +26,7 @@ Számok betűvel írva az I18n könyvtár segítségével.
* Italiano**
* Nederlands**
* Swedish**
* English (British)**

** Experimental

Expand Down Expand Up @@ -130,10 +131,11 @@ Számok betűvel írva az I18n könyvtár segítségével.
=> "двадцать одна целая и семьдесят семь сотых"
=> "двадцять одна цiла i сiмдесят сiм сотих"
=> "huszonegy egész hetvenhét század"
=> "twenty-one point seven seven"

== Language options / Языковые опции

* English
* English / British

Ordinal form: (ordinal: [true || false])

Expand All @@ -155,6 +157,9 @@ Számok betűvel írva az I18n könyvtár segítségével.
I18n.with_locale(:en) { 0.7.to_words remove_zero: true }
=> "seven tenths"

I18n.with_locale(:en) { [0.1, 0.31, 0.12].to_words remove_zero: true }
=> ["one tenth", "thirty-one hundredths", "twelve hundredths"]

* Russian

Change gender form: (gender: [:female || :male || :neuter])
Expand Down
2 changes: 1 addition & 1 deletion lib/numbers_and_words/core_ext/array.rb
@@ -1,6 +1,6 @@
class Array
def to_words options = {}
map &:to_words
map{|element| element.to_words options}
end

def to_figures
Expand Down
55 changes: 55 additions & 0 deletions lib/numbers_and_words/i18n/locales/numbers.en-GB.yml
@@ -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
18 changes: 5 additions & 13 deletions lib/numbers_and_words/strategies/array_joiner.rb
@@ -1,29 +1,21 @@
require 'numbers_and_words/strategies/array_joiner/languages'

module NumbersAndWords
module Strategies
module ArrayJoiner
class Base

attr_accessor :options, :elements
attr_accessor :options, :elements, :translations, :language

def initialize elements, options = {}
@elements = elements
@options = options
@translations = Translations.factory
@language = Languages.factory(self)
end

def run
around { elements.join union_separator }
end

private

def union_separator
separator = options[:union_separator] || @translations.union || ''
" #{separator} " if separator.present?
end

def around
yield
language.join
end
end
end
Expand Down
27 changes: 27 additions & 0 deletions lib/numbers_and_words/strategies/array_joiner/languages.rb
@@ -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 lib/numbers_and_words/strategies/array_joiner/languages/base.rb
@@ -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 lib/numbers_and_words/strategies/array_joiner/languages/en.rb
@@ -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 lib/numbers_and_words/strategies/array_joiner/languages/en_gb.rb
@@ -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
@@ -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 lib/numbers_and_words/strategies/array_joiner/languages/hu.rb
@@ -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 lib/numbers_and_words/strategies/array_joiner/languages/ru.rb
@@ -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 lib/numbers_and_words/strategies/array_joiner/languages/ua.rb
@@ -0,0 +1,10 @@
module NumbersAndWords
module Strategies
module ArrayJoiner
module Languages
class Ua < Base
end
end
end
end
end
@@ -1,5 +1,6 @@
require 'numbers_and_words/strategies/figures_converter/decorators/base'
require 'numbers_and_words/strategies/figures_converter/decorators/en'
require 'numbers_and_words/strategies/figures_converter/decorators/en_gb'
require 'numbers_and_words/strategies/figures_converter/decorators/ru'
require 'numbers_and_words/strategies/figures_converter/decorators/hu'
require 'numbers_and_words/strategies/figures_converter/decorators/ua'
Expand Down Expand Up @@ -30,7 +31,7 @@ def decorator_class_name method_name
end

def language_class_name
::I18n.locale.to_s.titleize.gsub ' ', '::'
::I18n.locale.to_s.titleize.gsub ' ', ''
end
end
end
Expand Down
Expand Up @@ -12,15 +12,15 @@ def run
private

def fraction_significance
@strategy.translations.micros full_fraction.fraction_capacity, figures.reverse.join.to_i
@strategy.translations.micros full_fraction.fraction_capacity, figures.join.to_i
end

def full_fraction
(0..zero_length).inject(figures.clone) { |result, el| result.unshift '0' }.to_figures
(0..zero_length).inject(figures.clone) { |result, el| result.unshift 0 }.to_figures
end

def figures
@strategy.figures
@strategy.figures.reverse
end

def zero_length
Expand Down
@@ -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'
@@ -0,0 +1,12 @@
module NumbersAndWords
module Strategies
module FiguresConverter
module Decorators
module EnGb
class Base < En::Base
end
end
end
end
end
end
@@ -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
@@ -0,0 +1,12 @@
module NumbersAndWords
module Strategies
module FiguresConverter
module Decorators
module EnGb
class Integral < En::Integral
end
end
end
end
end
end

0 comments on commit 58bc280

Please sign in to comment.