Sha256: 14ae1b25abf6fe6eeb591a238c0b2daaa179448ca3160ecd6d3832ce305bb471

Contents?: true

Size: 676 Bytes

Versions: 12

Compression:

Stored size: 676 Bytes

Contents

module MuckCommerce
  module CurrencyMethods

    # Assumes a field named amount
    def amount_dollars= val
      self.amount = dollars_to_cents(val)
    end

    # Assumes a field named amount
    def amount_dollars
      cents_to_dollars(self.amount)
    end
    
    # Assumes a field named amount
    # Get the order amount as a formatted currency instead of as cents. 
    def amount_price
      format_currency(self.amount)
    end

    protected

      def format_currency(val)
        format("%.2f", cents_to_dollars(val))
      end

      def cents_to_dollars(val)
        val * 0.01
      end

      def dollars_to_cents(val)
        val * 100
      end

  end

end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
muck-commerce-3.0.1 lib/muck-commerce/share/currency_methods.rb
muck-commerce-0.2.8 lib/muck_commerce/currency_methods.rb
muck-commerce-0.2.7 lib/muck_commerce/currency_methods.rb
muck-commerce-0.2.6 lib/muck_commerce/currency_methods.rb
muck-commerce-0.2.5 lib/muck_commerce/currency_methods.rb
muck-commerce-0.2.4 lib/muck_commerce/currency_methods.rb
muck-commerce-0.2.3 lib/muck_commerce/currency_methods.rb
muck-commerce-0.2.2 lib/muck_commerce/currency_methods.rb
muck-commerce-0.2.1 lib/muck_commerce/currency_methods.rb
muck-commerce-0.2.0 lib/muck_commerce/currency_methods.rb
muck-commerce-0.1.9 lib/muck_commerce/currency_methods.rb
muck-commerce-0.1.8 lib/muck_commerce/currency_methods.rb