Class: Quantify::Unit::CompoundBaseUnit
- Inherits:
-
Object
- Object
- Quantify::Unit::CompoundBaseUnit
- Defined in:
- lib/quantify/unit/compound_base_unit.rb
Instance Attribute Summary collapse
-
#index ⇒ Object
Container class for compound unit base units.
-
#unit ⇒ Object
Container class for compound unit base units.
Instance Method Summary collapse
- #dimensions ⇒ Object
- #factor ⇒ Object
-
#initialize(unit, index = 1) ⇒ CompoundBaseUnit
constructor
A new instance of CompoundBaseUnit.
- #initialize_copy(source) ⇒ Object
- #is_base_quantity_si_unit? ⇒ Boolean
- #is_base_unit? ⇒ Boolean
- #is_benchmark_unit? ⇒ Boolean
- #is_denominator? ⇒ Boolean
- #is_derived_unit? ⇒ Boolean
-
#is_dimensionless? ⇒ Boolean
Only refers to the unit index, rather than the dimensions configuration of the actual unit.
- #is_non_si_unit? ⇒ Boolean
- #is_numerator? ⇒ Boolean
- #is_prefixed_unit? ⇒ Boolean
- #is_si_unit? ⇒ Boolean
- #label(reciprocal = false) ⇒ Object
- #measures ⇒ Object
-
#name(reciprocal = false) ⇒ Object
Absolute index as names always contain ‘per’ before denominator units.
- #pluralized_name ⇒ Object
- #symbol(reciprocal = false) ⇒ Object
Constructor Details
#initialize(unit, index = 1) ⇒ CompoundBaseUnit
Returns a new instance of CompoundBaseUnit.
16 17 18 19 20 |
# File 'lib/quantify/unit/compound_base_unit.rb', line 16 def initialize(unit,index=1) @unit = Unit.match(unit) || raise(Exceptions::InvalidUnitError, "Base unit not known: #{unit}") raise Exceptions::InvalidUnitError, "Base unit cannot be compound unit" if @unit.is_a? Compound @index = index end |
Instance Attribute Details
#index ⇒ Object
Container class for compound unit base units. Each instance is represented by a unit and an index, i.e. a unit raised to some power. If no index is present, 1 is assumed.
Instances of this class can be used to initialize base units, and are the structures which hold base units within compound units
14 15 16 |
# File 'lib/quantify/unit/compound_base_unit.rb', line 14 def index @index end |
#unit ⇒ Object
Container class for compound unit base units. Each instance is represented by a unit and an index, i.e. a unit raised to some power. If no index is present, 1 is assumed.
Instances of this class can be used to initialize base units, and are the structures which hold base units within compound units
14 15 16 |
# File 'lib/quantify/unit/compound_base_unit.rb', line 14 def unit @unit end |
Instance Method Details
#dimensions ⇒ Object
22 23 24 |
# File 'lib/quantify/unit/compound_base_unit.rb', line 22 def dimensions @unit.dimensions ** @index end |
#factor ⇒ Object
50 51 52 |
# File 'lib/quantify/unit/compound_base_unit.rb', line 50 def factor @unit.factor ** @index end |
#initialize_copy(source) ⇒ Object
94 95 96 |
# File 'lib/quantify/unit/compound_base_unit.rb', line 94 def initialize_copy(source) instance_variable_set("@unit", @unit.clone) end |
#is_base_quantity_si_unit? ⇒ Boolean
66 67 68 |
# File 'lib/quantify/unit/compound_base_unit.rb', line 66 def is_base_quantity_si_unit? @unit.is_base_quantity_si_unit? end |
#is_base_unit? ⇒ Boolean
70 71 72 |
# File 'lib/quantify/unit/compound_base_unit.rb', line 70 def is_base_unit? @unit.is_base_unit? end |
#is_benchmark_unit? ⇒ Boolean
74 75 76 |
# File 'lib/quantify/unit/compound_base_unit.rb', line 74 def is_benchmark_unit? @unit.is_benchmark_unit? end |
#is_denominator? ⇒ Boolean
58 59 60 |
# File 'lib/quantify/unit/compound_base_unit.rb', line 58 def is_denominator? @index < 0 end |
#is_derived_unit? ⇒ Boolean
90 91 92 |
# File 'lib/quantify/unit/compound_base_unit.rb', line 90 def is_derived_unit? @unit.is_derived_unit? end |
#is_dimensionless? ⇒ Boolean
Only refers to the unit index, rather than the dimensions configuration of the actual unit
29 30 31 |
# File 'lib/quantify/unit/compound_base_unit.rb', line 29 def is_dimensionless? @index == 0 end |
#is_non_si_unit? ⇒ Boolean
82 83 84 |
# File 'lib/quantify/unit/compound_base_unit.rb', line 82 def is_non_si_unit? @unit.is_non_si_unit? end |
#is_numerator? ⇒ Boolean
54 55 56 |
# File 'lib/quantify/unit/compound_base_unit.rb', line 54 def is_numerator? @index > 0 end |
#is_prefixed_unit? ⇒ Boolean
86 87 88 |
# File 'lib/quantify/unit/compound_base_unit.rb', line 86 def is_prefixed_unit? @unit.is_prefixed_unit? end |
#is_si_unit? ⇒ Boolean
78 79 80 |
# File 'lib/quantify/unit/compound_base_unit.rb', line 78 def is_si_unit? @unit.is_si_unit? end |
#label(reciprocal = false) ⇒ Object
46 47 48 |
# File 'lib/quantify/unit/compound_base_unit.rb', line 46 def label(reciprocal=false) @unit.label + index_as_string(reciprocal) end |
#measures ⇒ Object
62 63 64 |
# File 'lib/quantify/unit/compound_base_unit.rb', line 62 def measures dimensions.describe end |
#name(reciprocal = false) ⇒ Object
Absolute index as names always contain ‘per’ before denominator units
34 35 36 |
# File 'lib/quantify/unit/compound_base_unit.rb', line 34 def name(reciprocal=false) name_to_power(@unit.name, @index.abs) end |
#pluralized_name ⇒ Object
38 39 40 |
# File 'lib/quantify/unit/compound_base_unit.rb', line 38 def pluralized_name name_to_power(@unit.pluralized_name, @index.abs) end |
#symbol(reciprocal = false) ⇒ Object
42 43 44 |
# File 'lib/quantify/unit/compound_base_unit.rb', line 42 def symbol(reciprocal=false) @unit.symbol + index_as_string(reciprocal) end |