Class: CurrencyInWords::EnTexterizer
- Inherits:
-
Object
- Object
- CurrencyInWords::EnTexterizer
- Defined in:
- lib/currency-in-words.rb
Overview
:nodoc: all This is the strategy class for English language
Instance Method Summary collapse
Instance Method Details
#texterize(context) ⇒ Object
140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 |
# File 'lib/currency-in-words.rb', line 140 def texterize context int_part, dec_part = context.number_parts connector = context.[:connector] int_unit_one = context.[:currency][:unit][:one] int_unit_many = context.[:currency][:unit][:many] dec_unit_one = context.[:currency][:decimal][:one] dec_unit_many = context.[:currency][:decimal][:many] @skip_and = context.[:skip_and] || false @delimiter = context.[:delimiter] || false unless int_unit_many int_unit_many = int_unit_one+'s' end unless dec_unit_many dec_unit_many = dec_unit_one+'s' end int_unit = int_part > 1 ? int_unit_many : int_unit_one dec_unit = dec_part > 1 ? dec_unit_many : dec_unit_one texterized_int_part = (texterize_by_group(int_part).compact << int_unit).flatten.join(' ') texterized_dec_part = (texterize_by_group(dec_part).compact << dec_unit).flatten.join(' ') if dec_part.zero? texterized_int_part else texterized_int_part << connector << texterized_dec_part end end |