Sha256: 554a795ecfe336600eb426252e8075b93639071ca3f48d7906c5e2549c21d897

Contents?: true

Size: 627 Bytes

Versions: 2

Compression:

Stored size: 627 Bytes

Contents

# encoding: utf-8

class Hash
  def to_money(currency = nil)
    money_hash = self.respond_to?(:with_indifferent_access) ? self.with_indifferent_access : self

    hash_currency = if money_hash[:currency].is_a?(Hash)
                      money_hash[:currency][:iso_code]
                    elsif money_hash[:currency_iso] && !money_hash[:currency_iso].empty?
                      money_hash[:currency_iso]
                    else
                      money_hash[:currency]
                    end

    Money.new(money_hash[:cents] || money_hash[:fractional], hash_currency || currency || Money.default_currency)
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
monetize-1.13.0 lib/monetize/core_extensions/hash.rb
monetize-1.12.0 lib/monetize/core_extensions/hash.rb