Class: Quantity::OperationInfo
- Inherits:
-
Object
- Object
- Quantity::OperationInfo
- Includes:
- Calculable
- Defined in:
- lib/unitmanager/quantity.rb
Instance Attribute Summary collapse
-
#first_operand ⇒ Object
readonly
Returns the value of attribute first_operand.
-
#operation ⇒ Object
readonly
Returns the value of attribute operation.
-
#second_operand ⇒ Object
readonly
Returns the value of attribute second_operand.
Instance Method Summary collapse
-
#initialize(first_operand, second_operand, operation) ⇒ OperationInfo
constructor
A new instance of OperationInfo.
- #to_quantity(calc) ⇒ Object
Methods included from Calculable
Methods included from Quantifiable
Constructor Details
#initialize(first_operand, second_operand, operation) ⇒ OperationInfo
Returns a new instance of OperationInfo.
97 98 99 100 101 102 103 104 105 |
# File 'lib/unitmanager/quantity.rb', line 97 def initialize(first_operand, second_operand, operation) raise "Operand is not Quantifiable" unless quantifiable?(first_operand) && quantifiable?(second_operand) @first_operand = first_operand @second_operand = second_operand @operation = operation end |
Instance Attribute Details
#first_operand ⇒ Object (readonly)
Returns the value of attribute first_operand.
95 96 97 |
# File 'lib/unitmanager/quantity.rb', line 95 def first_operand @first_operand end |
#operation ⇒ Object (readonly)
Returns the value of attribute operation.
95 96 97 |
# File 'lib/unitmanager/quantity.rb', line 95 def operation @operation end |
#second_operand ⇒ Object (readonly)
Returns the value of attribute second_operand.
95 96 97 |
# File 'lib/unitmanager/quantity.rb', line 95 def second_operand @second_operand end |
Instance Method Details
#to_quantity(calc) ⇒ Object
107 108 109 110 111 112 |
# File 'lib/unitmanager/quantity.rb', line 107 def to_quantity(calc) first_operand = @first_operand.to_quantity(calc) second_operand = @second_operand.to_quantity(calc) return apply_operator(first_operand, second_operand, @operation) end |