Class: Money::MoneyFormatter
Overview
Instance Attribute Summary collapse
-
#bank ⇒ Object
readonly
Returns the value of attribute bank.
-
#locale ⇒ Object
readonly
Returns the value of attribute locale.
-
#money ⇒ Object
readonly
Returns the value of attribute money.
Instance Method Summary collapse
-
#initialize(money, options = {}) ⇒ MoneyFormatter
constructor
A new instance of MoneyFormatter.
- #to_s ⇒ Object
Constructor Details
#initialize(money, options = {}) ⇒ MoneyFormatter
Returns a new instance of MoneyFormatter.
22 23 24 25 26 27 28 29 |
# File 'lib/money/money_formatter.rb', line 22 def initialize(money, = {}) @money = money @locale = ([:locale] || Money.default_locale).to_s @locale.gsub!(/_/, '-') @bank = [:bank] || Money.default_bank @format = FORMATS[@locale] @currency_symbol = CURRENCIES[@money.currency][:symbol] end |
Instance Attribute Details
#bank ⇒ Object (readonly)
Returns the value of attribute bank.
20 21 22 |
# File 'lib/money/money_formatter.rb', line 20 def bank @bank end |
#locale ⇒ Object (readonly)
Returns the value of attribute locale.
20 21 22 |
# File 'lib/money/money_formatter.rb', line 20 def locale @locale end |
#money ⇒ Object (readonly)
Returns the value of attribute money.
20 21 22 |
# File 'lib/money/money_formatter.rb', line 20 def money @money end |
Instance Method Details
#to_s ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/money/money_formatter.rb', line 31 def to_s unless @money.nan? pattern = @money.positive? || @money.zero? ? @format[:pos_pattern] : @format[:neg_pattern] precision = CURRENCIES[@money.currency][:decimal_digits] # @format[:decimal_digits] # divisor = 10 ** precision #if @money.amount.round(2) == 1.77 # puts "" # puts "Money = #{@money.amount} #{@money.currency}" # puts " Prec: #{precision}" # puts " Divi: #{divisor}" #end number = number_with_precision( @money.amount.to_f.abs, # / divisor, precision, @format[:decimal_sep], @format[:group_sep]) pattern.gsub("n", number).gsub("$", @currency_symbol) end end |