Class: Spree::Money
- Inherits:
-
Object
- Object
- Spree::Money
- Defined in:
- lib/spree/money.rb
Instance Attribute Summary collapse
-
#money ⇒ Object
readonly
Returns the value of attribute money.
Instance Method Summary collapse
- #==(obj) ⇒ Object
-
#initialize(amount, options = {}) ⇒ Money
constructor
A new instance of Money.
- #to_html(options = { :html => true }) ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(amount, options = {}) ⇒ Money
7 8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/spree/money.rb', line 7 def initialize(amount, ={}) @money = ::Money.parse([amount, ([:currency] || Spree::Config[:currency])].join) = {} [:with_currency] = Spree::Config[:display_currency] [:symbol_position] = Spree::Config[:currency_symbol_position].to_sym [:no_cents] = Spree::Config[:hide_cents] [:decimal_mark] = Spree::Config[:currency_decimal_mark] [:thousands_separator] = Spree::Config[:currency_thousands_separator] .merge!() # Must be a symbol because the Money gem doesn't do the conversion [:symbol_position] = [:symbol_position].to_sym end |
Instance Attribute Details
#money ⇒ Object (readonly)
Returns the value of attribute money.
5 6 7 |
# File 'lib/spree/money.rb', line 5 def money @money end |
Instance Method Details
#==(obj) ⇒ Object
34 35 36 |
# File 'lib/spree/money.rb', line 34 def ==(obj) @money == obj.money end |
#to_html(options = { :html => true }) ⇒ Object
24 25 26 27 28 29 30 31 32 |
# File 'lib/spree/money.rb', line 24 def to_html( = { :html => true }) output = @money.format(.merge()) if [:html] # 1) prevent blank, breaking spaces # 2) prevent escaping of HTML character entities output = output.gsub(" ", " ").html_safe end output end |
#to_s ⇒ Object
20 21 22 |
# File 'lib/spree/money.rb', line 20 def to_s @money.format() end |