Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

English fixes and tests #9

Merged
merged 6 commits into from
Mar 24, 2012
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/initializers/i18n.rb
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
require "i18n/backend/pluralization"
I18n::Backend::Simple.send(:include, I18n::Backend::Pluralization)
I18n::Backend::Simple.send(:include, I18n::Backend::Pluralization)
5 changes: 2 additions & 3 deletions lib/locales/numbers.en.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
en:
numbers:
ones: [nought, one, two, three, four, five, six, seven, eight, nine]
ones: [zero, one, two, three, four, five, six, seven, eight, nine]
teens: [ten, eleven, twelve, thirteen, fourteen, fifteen, sixteen, seventeen, eighteen, nineteen]
tens: [nought, ten, twenty, thirty, forty, fifty, sixty, seventy, nought, ninety]
union: and
tens: [zero, ten, twenty, thirty, forty, fifty, sixty, seventy, nought, ninety]
hundreds: hundred
mega: [ones, thousand, million, billion, trillion, quadrillion, quintillion, sextillion, septillion, octillion, nonillion, decillion]
20 changes: 10 additions & 10 deletions lib/numbers_and_words/strategies/en.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,18 @@ module NumbersAndWords
module Strategies
class En < Base
include NumbersAndWords::TranslationsHelpers::En

attr_accessor :figures_in_previous_capacity

def convert figures
@figures = figures.reverse

@words = strings
@words.empty? ? zero : @words.reverse.join(' ')
end

private

def strings
if figures.capacity_count
complex_to_words
Expand All @@ -25,27 +25,27 @@ def strings
[]
end
end

def complex_to_words
words = []
figures.capacity_count.times do |capacity|
number_in_capacity_by_words = save_parent_figures do |parent_figures|
@figures = parent_figures.figures_array_in_capacity(capacity)
strings
end

unless number_in_capacity_by_words.empty?
words.push translation_megs(capacity) if 0 < capacity
words += number_in_capacity_by_words
end
end
words
end

def simple_hundreds_to_words
simple_to_words + [translation_hundreds(figures.hundreds)]
end

def simple_to_words
if figures.teens
[translation_teens(figures.ones)]
Expand All @@ -59,7 +59,7 @@ def simple_to_words
[]
end
end

def save_parent_figures
parent_figures = @figures
result = yield(parent_figures)
Expand Down
10 changes: 5 additions & 5 deletions lib/numbers_and_words/translations_helpers/en.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,6 @@ module En

private

def translation_megs capacity
t(:mega)[capacity]
end

def translation_teens number
t(:teens)[number]
end
Expand All @@ -33,8 +29,12 @@ def translation_hundreds number
[t(:ones)[number], t(:hundreds)].join ' '
end

def translation_megs capacity
t(:mega)[capacity]
end

def zero
t(:ones_male)[0]
t(:ones)[0]
end
end
end
Expand Down
26 changes: 26 additions & 0 deletions spec/numbers_and_words/array/en_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
require 'spec_helper'

describe Array do
around :each do |example|
I18n.with_locale(:en) do
example.run
end
end

describe 'to_words' do
context 'simple example' do
subject { [1, 2, 3] }
its(:to_words) { should == 3.times.map { |number| t(:ones)[number + 1] } }
end

context 'complex example' do
subject { [101, 21, 13] }

its(:to_words) { should == [
[t(:ones)[1], t(:hundreds), t(:ones)[1]].join(' '),
[t(:tens)[2], t(:ones)[1]].join('-'),
t(:teens)[3]
] }
end
end
end
5 changes: 3 additions & 2 deletions spec/numbers_and_words/array/ru_spec.rb
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
require './spec/spec_helper'
require 'spec_helper'

describe Array do

around :each do |example|
I18n.with_locale(:ru) do
example.run
end
end


describe 'to_words' do
context 'simple example' do
subject { [1, 2, 3] }
Expand All @@ -24,4 +24,5 @@
] }
end
end

end
Loading