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
Returns a new instance of Money.
9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/spree/money.rb', line 9 def initialize(amount, ={}) @money = ::Money.parse([amount, ([:currency] || Spree::Config[:currency])].join) @options = {} @options[:with_currency] = Spree::Config[:display_currency] @options[:symbol_position] = Spree::Config[:currency_symbol_position].to_sym @options[:no_cents] = Spree::Config[:hide_cents] @options[:decimal_mark] = Spree::Config[:currency_decimal_mark] @options[:thousands_separator] = Spree::Config[:currency_thousands_separator] @options.merge!() # Must be a symbol because the Money gem doesn't do the conversion @options[:symbol_position] = @options[: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
36 37 38 |
# File 'lib/spree/money.rb', line 36 def ==(obj) @money == obj.money end |
#to_html(options = { :html => true }) ⇒ Object
26 27 28 29 30 31 32 33 34 |
# File 'lib/spree/money.rb', line 26 def to_html( = { :html => true }) output = @money.format(@options.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
22 23 24 |
# File 'lib/spree/money.rb', line 22 def to_s @money.format(@options) end |