Class: Quantity::Quantity
- Inherits:
-
Object
- Object
- Quantity::Quantity
- Includes:
- CalculationSupport
- Defined in:
- lib/unitmanager/quantity.rb
Instance Attribute Summary collapse
-
#calc ⇒ Object
readonly
Returns the value of attribute calc.
-
#unit ⇒ Object
readonly
Returns the value of attribute unit.
-
#value ⇒ Object
readonly
Returns the value of attribute value.
Instance Method Summary collapse
-
#[](symbol) ⇒ Object
:dividends - returns an array of symbols representing dividend part of unit definition.
-
#initialize(calc, params) ⇒ Quantity
constructor
A new instance of Quantity.
- #to_quantity(calc) ⇒ Object
Methods included from CalculationSupport
Methods included from Quantifiable
Constructor Details
#initialize(calc, params) ⇒ Quantity
Returns a new instance of Quantity.
114 115 116 117 118 |
# File 'lib/unitmanager/quantity.rb', line 114 def initialize(calc, params) @calc = calc @unit = params[:unit] || Unit::ComposedUnit.new({}) @value = params[:value] || 0.0 end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class Quantity::CalculationSupport
Instance Attribute Details
#calc ⇒ Object (readonly)
Returns the value of attribute calc.
112 113 114 |
# File 'lib/unitmanager/quantity.rb', line 112 def calc @calc end |
#unit ⇒ Object (readonly)
Returns the value of attribute unit.
112 113 114 |
# File 'lib/unitmanager/quantity.rb', line 112 def unit @unit end |
#value ⇒ Object (readonly)
Returns the value of attribute value.
112 113 114 |
# File 'lib/unitmanager/quantity.rb', line 112 def value @value end |
Instance Method Details
#[](symbol) ⇒ Object
:dividends - returns an array of symbols representing dividend part of
unit definition.
:divisors - returns an array of symbols representing divisor part of
unit definition.
:string - string representation of the unit of measure.
:value - returns quantity value
135 136 137 138 139 |
# File 'lib/unitmanager/quantity.rb', line 135 def [] (symbol) return value if symbol == :value @unit[symbol] end |
#to_quantity(calc) ⇒ Object
120 121 122 123 124 |
# File 'lib/unitmanager/quantity.rb', line 120 def to_quantity(calc) raise "Incompatible Argument." + "Both operands must be created by the same calculator" unless @calc == calc self end |