lib/papla.rb in papla-0.0.3 vs lib/papla.rb in papla-0.0.4
- old
+ new
@@ -1,22 +1,26 @@
require 'papla/backend'
require 'papla/version'
module Papla
- # Converts a number to Polish words, capitalizing
- # the first letter of the whole phrase.
+ # Converts a number to Polish or English words,
+ # capitalizing the first letter of the whole phrase.
#
+ # Localisation is provided by <tt>I18n</tt>, the language
+ # of the result depends on <tt>I18n.locale</tt>.
+ #
# Currently numbers from 0 up to 999 999 999
# are supported. If you pass a bigger number,
# an <tt>ArgumentError</tt> is raised.
#
# To convert a number, simply call:
#
# Papla[your_number]
#
# Examples:
#
+ # I18n.locale # => :pl
# Papla[0] # => "Zero"
# Papla[22] # => "Dwadzieścia dwa"
# Papla[150] # => "Sto pięćdziesiąt"
# Papla[999] # => "Dziewięćset dziewięćdziesiąt dziewięć"
# Papla[12345] # => "Dwanaście tysięcy trzysta czterdzieści pięć"
@@ -33,11 +37,11 @@
# Papla[1.0] # => "Jeden 00/100"
# Papla[87.654321] # => "Osiemdziesiąt siedem 65/100"
# Papla[2.999] # => "Trzy 00/100"
#
# @param [Fixnum] number the number to convert
- # @return [String] the phrase in Polish
+ # @return [String] the phrase in Polish or English
def self.[](number)
validate!(number)
number = prepare(number)
basic_number = number.to_i
basic_phrase = build_basic_phrase(basic_number)
@@ -114,17 +118,11 @@
def self.append_cents(basic_phrase, number)
cents = 100 * (number - number.to_i)
spell_cents(basic_phrase, cents)
end
- @backends = {}
-
def self.backend
- @backends[locale] ||= Backend.new(locale)
- end
-
- def self.locale
- :pl
+ @backend ||= Backend.new
end
def self.spell_zero; backend.zero; end
def self.spell_ones(index); backend.ones(index); end
def self.spell_tens(index); backend.tens(index); end