Sha256: cfbd20ab30013d463fb54efeb0af0ccefefa098c99d180d1a0097af761d9b16f

Contents?: true

Size: 1.88 KB

Versions: 17

Compression:

Stored size: 1.88 KB

Contents

class Money
  module Constructors

    # Create a new money object with value 0.
    #
    # @param [Currency, String, Symbol] currency The currency to use.
    #
    # @return [Money]
    #
    # @example
    #   Money.empty #=> #<Money @fractional=0>
    def empty(currency = default_currency)
      new(0, currency)
    end
    alias_method :zero, :empty


    # Creates a new Money object of the given value, using the Canadian
    # dollar currency.
    #
    # @param [Integer] cents The cents value.
    #
    # @return [Money]
    #
    # @example
    #   n = Money.ca_dollar(100)
    #   n.cents    #=> 100
    #   n.currency #=> #<Money::Currency id: cad>
    def ca_dollar(cents)
      new(cents, "CAD")
    end
    alias_method :cad, :ca_dollar


    # Creates a new Money object of the given value, using the American dollar
    # currency.
    #
    # @param [Integer] cents The cents value.
    #
    # @return [Money]
    #
    # @example
    #   n = Money.us_dollar(100)
    #   n.cents    #=> 100
    #   n.currency #=> #<Money::Currency id: usd>
    def us_dollar(cents)
      new(cents, "USD")
    end
    alias_method :usd, :us_dollar


    # Creates a new Money object of the given value, using the Euro currency.
    #
    # @param [Integer] cents The cents value.
    #
    # @return [Money]
    #
    # @example
    #   n = Money.euro(100)
    #   n.cents    #=> 100
    #   n.currency #=> #<Money::Currency id: eur>
    def euro(cents)
      new(cents, "EUR")
    end
    alias_method :eur, :euro


    # Creates a new Money object of the given value, in British pounds.
    #
    # @param [Integer] pence The pence value.
    #
    # @return [Money]
    #
    # @example
    #   n = Money.pound_sterling(100)
    #   n.fractional    #=> 100
    #   n.currency #=> #<Money::Currency id: gbp>
    def pound_sterling(pence)
      new(pence, "GBP")
    end
    alias_method :gbp, :pound_sterling

  end
end

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
money-6.19.0 lib/money/money/constructors.rb
money-6.18.0 lib/money/money/constructors.rb
money-6.17.0 lib/money/money/constructors.rb
money-6.16.0 lib/money/money/constructors.rb
money-6.14.1 lib/money/money/constructors.rb
money-6.14.0 lib/money/money/constructors.rb
money-6.13.8 lib/money/money/constructors.rb
money-6.13.7 lib/money/money/constructors.rb
money-6.13.6 lib/money/money/constructors.rb
money-6.13.5 lib/money/money/constructors.rb
money-6.13.4 lib/money/money/constructors.rb
money-6.13.3 lib/money/money/constructors.rb
money-6.13.2 lib/money/money/constructors.rb
money-6.13.1 lib/money/money/constructors.rb
money-6.13.0 lib/money/money/constructors.rb
money-6.12.0 lib/money/money/constructors.rb
money-6.8.0 lib/money/money/constructors.rb