Sha256: 34e9f9ec368b5f58d87a2f2527844580827e7cffc7f4ddcd2b4dcb8dd397672a

Contents?: true

Size: 601 Bytes

Versions: 1

Compression:

Stored size: 601 Bytes

Contents

class IndianRupee
  def initialize(value, unit = nil)
    @value = value
    @unit = unit
    @paise = convert_to_paise if @unit
  end

  def convert_to_paise
    case @unit
      when :inr
        @value * 100
      when :paise
        @value
      else
        @value
    end
  end

  def to_paise
    @paise
  end

  def to_inr
    @paise / 100.0
  end
  alias :to_coin :to_inr

  def to_smallest
    to_paise
  end

  def smallest_to_coin
    @unit ||= :paise
    @paise = @value
    to_coin
  end

  def coin_to_smallest
    @unit ||= :inr
    @paise = convert_to_paise
    to_smallest
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
currency_units-0.1.6 lib/currency_units/currencies/indian_rupee.rb