Class: KitchenMeasures::Measure
- Inherits:
-
Object
- Object
- KitchenMeasures::Measure
- Defined in:
- lib/kitchen_measures/measure.rb
Defined Under Namespace
Classes: Unitless
Class Method Summary collapse
Instance Method Summary collapse
- #<=>(other) ⇒ Object
- #==(other) ⇒ Object
-
#initialize(quantity, unit) ⇒ Measure
constructor
A new instance of Measure.
- #to_s ⇒ Object
- #unitless? ⇒ Boolean
Constructor Details
#initialize(quantity, unit) ⇒ Measure
Returns a new instance of Measure.
14 15 16 17 |
# File 'lib/kitchen_measures/measure.rb', line 14 def initialize(quantity, unit) @quantity = quantity @unit = unit or raise ArgumentError("Missing unit") end |
Class Method Details
.with_unit(quantity, unit) ⇒ Object
19 20 21 |
# File 'lib/kitchen_measures/measure.rb', line 19 def self.with_unit(quantity, unit) new(quantity, unit) end |
.without_unit(quantity) ⇒ Object
23 24 25 |
# File 'lib/kitchen_measures/measure.rb', line 23 def self.without_unit(quantity) new(quantity, Unitless.instance) end |
Instance Method Details
#<=>(other) ⇒ Object
39 40 41 |
# File 'lib/kitchen_measures/measure.rb', line 39 def <=>(other) to_unitwise <=> other.to_unitwise end |
#==(other) ⇒ Object
31 32 33 34 35 36 37 |
# File 'lib/kitchen_measures/measure.rb', line 31 def ==(other) if unitless? quantity == other.quantity && unit == other.unit else to_unitwise == other.to_unitwise end end |
#to_s ⇒ Object
27 28 29 |
# File 'lib/kitchen_measures/measure.rb', line 27 def to_s [quantity, unit].join(" ").strip end |
#unitless? ⇒ Boolean
43 44 45 |
# File 'lib/kitchen_measures/measure.rb', line 43 def unitless? unit == Unitless.instance end |