#Rupee class models currency in Rupee and paise
class Rupee
include Comparable
  attr_reader :rupee, :paise

  def initialize rupee, paise
    @paise = paise
    @rupee = rupee
  end

  def <=> second_amount
    if(self.class == second_amount.class)
    return self.to_paise <=> second_amount.to_paise
    end
    nil
  end

  def to_paise
    @rupee*100 + @paise
  end

  def to_string
    "#{@rupee} Rs. #{@paise} P"
  end


  def + second_amount

    one_in_paise = self.to_paise
    two_in_paise = second_amount.to_paise
    sum_paise = one_in_paise + two_in_paise
    sum_rupee = sum_paise/100
    sum_paise = sum_paise % 100
    Rupee.new(sum_rupee, sum_paise)

  end

  def - second_amount

    one_in_paise = self.to_paise
    two_in_paise = second_amount.to_paise
    difference_paise = one_in_paise - two_in_paise
    if(difference_paise < 0)
      difference_rupee = -(difference_paise.magnitude / 100)
      difference_paise = -(difference_paise.magnitude % 100)

    else
      difference_rupee = difference_paise/100
      difference_paise = difference_paise % 100
    end

    Rupee.new(difference_rupee, difference_paise)
  end

  def == second_amount
    if (self.equal? second_amount)
      return true
    end

    if (!(self.class == second_amount.class))
      return false
    end

    if @rupee == second_amount.rupee && @paise == second_amount.paise
      return true
    end

    false
  end

  def eql?(second_amount)
    self.==(second_amount)
  end

  def hash
    [@rupee, @paise].hash * 37
  end

end


def sort entered_money

  entered_money.each do |x|
    entered_money.each do |y|
       if(x <=> y)
         #swap
       end
    end
  end

  #[Rupee.new(0,50),Rupee.new(1,50),Rupee.new(1,90)]

end