Sha256: e0ea4f37d8a8786b477ffe31d3f0d7a3a368f34cacdbbeca6b8f97732aaf03f4
Contents?: true
Size: 1.23 KB
Versions: 2
Compression:
Stored size: 1.23 KB
Contents
require 'money' module Spree class Money attr_reader :money delegate :cents, :to => :money def initialize(amount, options={}) @money = ::Money.parse([amount, (options[: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!(options) # Must be a symbol because the Money gem doesn't do the conversion @options[:symbol_position] = @options[:symbol_position].to_sym end def to_s @money.format(@options) end def to_html(options = { :html => true }) output = @money.format(@options.merge(options)) if options[:html] # 1) prevent blank, breaking spaces # 2) prevent escaping of HTML character entities output = output.gsub(" ", " ").html_safe end output end def as_json(*) to_s end def ==(obj) @money == obj.money end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
spree_core-2.1.2 | lib/spree/money.rb |
spree_core-2.0.6 | lib/spree/money.rb |