Module: Papla
- Defined in:
- lib/papla.rb,
lib/papla/backend.rb,
lib/papla/version.rb,
lib/papla/float_converter.rb,
lib/papla/money_converter.rb,
lib/papla/integer_converter.rb
Defined Under Namespace
Classes: Backend, FloatConverter, IntegerConverter, MoneyConverter
Constant Summary collapse
- VERSION =
'0.2.1'
Class Method Summary collapse
-
.[](number) ⇒ String
Converts a number to Polish or English words, capitalizing the first letter of the whole phrase.
Class Method Details
.[](number) ⇒ String
Converts a number to Polish or English words, capitalizing the first letter of the whole phrase.
Localisation is provided by I18n
, the language of the result depends on I18n.locale
.
Currently numbers from 0 up to 999 999 999 are supported. If you pass a bigger number, an ArgumentError
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ęć"
Papla[1_000_001] # => "Jeden milion jeden"
When given a Float
, Papla will assume that the decimal part represents cents. It will then round the number using Float#round
to two decimal places, and append the number of cents divided by hundred to the resulting string.
Example:
Papla[1.0] # => "Jeden 00/100"
Papla[87.654321] # => "Osiemdziesiąt siedem 65/100"
Papla[2.999] # => "Trzy 00/100"
If you’re using the ‘money` gem, you can pass in an instance of `Money` to Papla. The returned string will contain the dollars part as words, the cents part as ’xx/100’ and the currency string (e.g. ‘EUR`).
Example:
eleven_and_a_half_pounds = Money.new(1150, 'GBP')
Papla[eleven_and_a_half_pounds] # => "Jedenaście 50/100 GBP"
I18n.locale = :en
discounted_price = Money.new(9999, 'PLN')
Papla[discounted_price] # => "Ninety nine 99/100 PLN"
60 61 62 63 |
# File 'lib/papla.rb', line 60 def self.[](number) converter = converter_for(number) converter.new.convert(number) end |