class VlatkoDawanda::Currency

Attributes

iso_code[R]
rate[R]

Public Class Methods

new(options = {}) click to toggle source
# File lib/vlatko_dawanda/currency.rb, line 7
def initialize(options = {})
  @iso_code = options[:iso_code]
  @rate = validate_rate(options[:rate])
end

Public Instance Methods

<=>(other) click to toggle source
# File lib/vlatko_dawanda/currency.rb, line 12
def <=>(other)
  rate <=> other.rate
end

Private Instance Methods

validate_rate(value) click to toggle source
# File lib/vlatko_dawanda/currency.rb, line 18
def validate_rate(value)
  rate = value.to_d rescue 0.to_d
  raise InvalidRate.new('please enter a positive float or integer as a rate') if rate <= 0
  rate
end