Class: Quantity::OperationInfo

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Calculable

#*, #+, #-, #/, #==, #coerce

Methods included from Quantifiable

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

Returns the value of attribute first_operand.



95
96
97
# File 'lib/unitmanager/quantity.rb', line 95

def first_operand
  @first_operand
end

#operationObject (readonly)

Returns the value of attribute operation.



95
96
97
# File 'lib/unitmanager/quantity.rb', line 95

def operation
  @operation
end

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