Class: Amazon::Associates::Measurement
- Includes:
- Comparable
- Defined in:
- lib/amazon-associates/types/measurement.rb
Instance Method Summary collapse
- #<=>(other) ⇒ Object
-
#initialize(value = nil, units = 'pixels') ⇒ Measurement
constructor
A new instance of Measurement.
- #to_i ⇒ Object
- #to_s ⇒ Object (also: #inspect)
Constructor Details
#initialize(value = nil, units = 'pixels') ⇒ Measurement
Returns a new instance of Measurement.
9 10 11 12 13 |
# File 'lib/amazon-associates/types/measurement.rb', line 9 def initialize(value = nil, units = 'pixels') @value = value && Float(value) @units = units.to_s normalize_hundredths end |
Instance Method Details
#<=>(other) ⇒ Object
27 28 29 30 31 |
# File 'lib/amazon-associates/types/measurement.rb', line 27 def <=>(other) return nil unless @units == other.units @value <=> other.value end |
#to_i ⇒ Object
23 24 25 |
# File 'lib/amazon-associates/types/measurement.rb', line 23 def to_i @value.round end |
#to_s ⇒ Object Also known as: inspect
15 16 17 18 19 20 |
# File 'lib/amazon-associates/types/measurement.rb', line 15 def to_s value = @value.whole? ? @value.to_i : @value #singularize here to avoid comparison problems units = @value == 1 ? @units.singularize : @units [value, units].join(' ') end |