Class: Quantity::OperationInfo
- Inherits:
-
Object
- Object
- Quantity::OperationInfo
- Includes:
- CalculationSupport
- 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 CalculationSupport
Methods included from Quantifiable
Constructor Details
#initialize(first_operand, second_operand, operation) ⇒ OperationInfo
Returns a new instance of OperationInfo.
77 78 79 80 81 82 83 84 85 |
# File 'lib/unitmanager/quantity.rb', line 77 def initialize(first_operand, second_operand, operation) raise "Operand #{first_operand.to_s} is not Quantifiable" unless quantifiable?(first_operand) raise "Operand #{second_operand.to_s} is not Quantifiable" unless quantifiable?(second_operand) @first_operand = first_operand @second_operand = second_operand @operation = operation end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class Quantity::CalculationSupport
Instance Attribute Details
#first_operand ⇒ Object (readonly)
Returns the value of attribute first_operand.
75 76 77 |
# File 'lib/unitmanager/quantity.rb', line 75 def first_operand @first_operand end |
#operation ⇒ Object (readonly)
Returns the value of attribute operation.
75 76 77 |
# File 'lib/unitmanager/quantity.rb', line 75 def operation @operation end |
#second_operand ⇒ Object (readonly)
Returns the value of attribute second_operand.
75 76 77 |
# File 'lib/unitmanager/quantity.rb', line 75 def second_operand @second_operand end |
Instance Method Details
#to_quantity(calc) ⇒ Object
87 88 89 90 91 92 |
# File 'lib/unitmanager/quantity.rb', line 87 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 |