Class: Amazon::Associates::Price
- Includes:
- Comparable
- Defined in:
- lib/amazon-associates/types/price.rb
Instance Attribute Summary collapse
-
#cents ⇒ Object
readonly
Returns the value of attribute cents.
-
#currency ⇒ Object
readonly
Returns the value of attribute currency.
Instance Method Summary collapse
- #<=>(other) ⇒ Object
-
#initialize(str = nil, cents = nil, currency = nil) ⇒ Price
constructor
A new instance of Price.
- #inspect ⇒ Object
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
#cents ⇒ Object (readonly)
Returns the value of attribute cents.
5 6 7 |
# File 'lib/amazon-associates/types/price.rb', line 5 def cents @cents end |
#currency ⇒ Object (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 |
#inspect ⇒ Object
24 25 26 |
# File 'lib/amazon-associates/types/price.rb', line 24 def inspect "#{to_s} #{currency}" end |