Class: Quantity::Quantity
- Inherits:
-
Object
- Object
- Quantity::Quantity
- Includes:
- Calculable
- 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 Calculable
Methods included from Quantifiable
Constructor Details
#initialize(calc, params) ⇒ Quantity
Returns a new instance of Quantity.
123 124 125 126 127 |
# File 'lib/unitmanager/quantity.rb', line 123 def initialize(calc, params) @calc = calc @unit = params[:unit] || Unit::ComposedUnit.new({}) @value = params[:value] || 0.0 end |
Instance Attribute Details
#calc ⇒ Object (readonly)
Returns the value of attribute calc.
121 122 123 |
# File 'lib/unitmanager/quantity.rb', line 121 def calc @calc end |
#unit ⇒ Object (readonly)
Returns the value of attribute unit.
121 122 123 |
# File 'lib/unitmanager/quantity.rb', line 121 def unit @unit end |
#value ⇒ Object (readonly)
Returns the value of attribute value.
121 122 123 |
# File 'lib/unitmanager/quantity.rb', line 121 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
144 145 146 147 148 |
# File 'lib/unitmanager/quantity.rb', line 144 def [] (symbol) return value if symbol == :value @unit[symbol] end |
#to_quantity(calc) ⇒ Object
129 130 131 132 133 |
# File 'lib/unitmanager/quantity.rb', line 129 def to_quantity(calc) raise "Incompatible Argument." + "Both operands must be created by the same calculator" unless @calc == calc self end |