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
- #as_json ⇒ Object
- #decimal_mark ⇒ Object
-
#initialize(amount, options = {}) ⇒ Money
constructor
A new instance of Money.
- #thousands_separator ⇒ Object
- #to_html(options = { html: true }) ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(amount, options = {}) ⇒ Money
Returns a new instance of Money.
20 21 22 23 |
# File 'lib/spree/money.rb', line 20 def initialize(amount, = {}) @money = Monetize.parse([amount, ([:currency] || Spree::Config[: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.
8 9 10 |
# File 'lib/spree/money.rb', line 8 def default_formatting_rules @default_formatting_rules end |
Instance Attribute Details
#money ⇒ Object (readonly)
Returns the value of attribute money.
16 17 18 |
# File 'lib/spree/money.rb', line 16 def money @money end |
Instance Method Details
#==(obj) ⇒ Object
53 54 55 |
# File 'lib/spree/money.rb', line 53 def ==(obj) @money == obj.money end |
#as_json ⇒ Object
39 40 41 |
# File 'lib/spree/money.rb', line 39 def as_json(*) to_s end |
#decimal_mark ⇒ Object
43 44 45 46 |
# File 'lib/spree/money.rb', line 43 def decimal_mark return @money.decimal_mark if @options[:decimal_mark].nil? @options[:decimal_mark] end |
#thousands_separator ⇒ Object
48 49 50 51 |
# File 'lib/spree/money.rb', line 48 def thousands_separator return @money.thousands_separator if @options[:thousands_separator].nil? @options[:thousands_separator] end |
#to_html(options = { html: true }) ⇒ Object
29 30 31 32 33 34 35 36 37 |
# File 'lib/spree/money.rb', line 29 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.sub(' ', ' ').html_safe end output end |
#to_s ⇒ Object
25 26 27 |
# File 'lib/spree/money.rb', line 25 def to_s @money.format(@options) end |