Class: Amazon::Associates::Price

Inherits:
ApiResult show all
Includes:
Comparable
Defined in:
lib/amazon-associates/types/price.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(str = nil, cents = nil, currency = nil) ⇒ Price

Returns a new instance of Price.



11
12
13
14
15
# File 'lib/amazon-associates/types/price.rb', line 11

def initialize(str = nil, cents = nil, currency = nil)
  @to_s = str.to_s
  @cents = cents ? Integer(cents) : 0
  @currency = currency.to_s
end

Instance Attribute Details

#centsObject (readonly)

Returns the value of attribute cents.



5
6
7
# File 'lib/amazon-associates/types/price.rb', line 5

def cents
  @cents
end

#currencyObject (readonly)

Returns the value of attribute currency.



5
6
7
# File 'lib/amazon-associates/types/price.rb', line 5

def currency
  @currency
end

Instance Method Details

#<=>(other) ⇒ Object



17
18
19
20
21
22
# File 'lib/amazon-associates/types/price.rb', line 17

def <=>(other)
  return nil if @currency.nil? or @cents.nil?
  return nil if @currency != other.currency

  @cents <=> other.cents
end

#inspectObject



24
25
26
# File 'lib/amazon-associates/types/price.rb', line 24

def inspect
  "#{to_s} #{currency}"
end