Class: Quantity::OperationInfo

Inherits:
Object
  • Object
show all
Includes:
CalculationSupport
Defined in:
lib/unitmanager/quantity.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from CalculationSupport

#==, #coerce, #method_missing

Methods included from Quantifiable

#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_operandObject (readonly)

Returns the value of attribute first_operand.



75
76
77
# File 'lib/unitmanager/quantity.rb', line 75

def first_operand
  @first_operand
end

#operationObject (readonly)

Returns the value of attribute operation.



75
76
77
# File 'lib/unitmanager/quantity.rb', line 75

def operation
  @operation
end

#second_operandObject (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