Class: Spree::Money
- Inherits:
-
Object
- Object
- Spree::Money
- Defined in:
- lib/spree/money.rb
Class Attribute Summary collapse
-
.default_formatting_rules ⇒ Object
Returns the value of attribute default_formatting_rules.
Instance Attribute Summary collapse
-
#money ⇒ Object
readonly
Returns the value of attribute money.
Instance Method Summary collapse
- #==(obj) ⇒ Object
- #amount_in_cents ⇒ Object
- #as_json ⇒ Object
- #decimal_mark ⇒ Object
-
#initialize(amount, options = {}) ⇒ Money
constructor
A new instance of Money.
- #thousands_separator ⇒ Object
-
#to_html(opts = { html: true }) ⇒ Object
1) prevent blank, breaking spaces 2) prevent escaping of HTML character entities.
- #to_s ⇒ Object
- #use_default_currency ⇒ Object
Constructor Details
#initialize(amount, options = {}) ⇒ Money
Returns a new instance of Money.
22 23 24 25 26 |
# File 'lib/spree/money.rb', line 22 def initialize(amount, = {}) use_default_currency @money = Monetize.parse([amount, ([:currency] || Spree::Store.default.default_currency)].join) @options = Spree::Money.default_formatting_rules.merge() end |
Class Attribute Details
.default_formatting_rules ⇒ Object
Returns the value of attribute default_formatting_rules.
9 10 11 |
# File 'lib/spree/money.rb', line 9 def default_formatting_rules @default_formatting_rules end |
Instance Attribute Details
#money ⇒ Object (readonly)
Returns the value of attribute money.
18 19 20 |
# File 'lib/spree/money.rb', line 18 def money @money end |
Instance Method Details
#==(obj) ⇒ Object
64 65 66 |
# File 'lib/spree/money.rb', line 64 def ==(obj) money == obj.money end |
#amount_in_cents ⇒ Object
28 29 30 |
# File 'lib/spree/money.rb', line 28 def amount_in_cents (cents / currency.subunit_to_unit.to_f * 100).round end |
#as_json ⇒ Object
52 53 54 |
# File 'lib/spree/money.rb', line 52 def as_json(*) to_s end |
#decimal_mark ⇒ Object
56 57 58 |
# File 'lib/spree/money.rb', line 56 def decimal_mark [:decimal_mark] || money.decimal_mark end |
#thousands_separator ⇒ Object
60 61 62 |
# File 'lib/spree/money.rb', line 60 def thousands_separator [:thousands_separator] || money.thousands_separator end |
#to_html(opts = { html: true }) ⇒ Object
1) prevent blank, breaking spaces 2) prevent escaping of HTML character entities
38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/spree/money.rb', line 38 def to_html(opts = { html: true }) # html option is deprecated and we need to fallback to html_wrap opts[:html_wrap] = opts[:html] opts.delete(:html) output = money.format(.merge(opts)) if opts[:html_wrap] output.gsub!(/<\/?[^>]*>/, '') # we don't want wrap every element in span output = output.sub(' ', ' ').html_safe end output end |
#to_s ⇒ Object
32 33 34 |
# File 'lib/spree/money.rb', line 32 def to_s money&.format() end |