Class: Unitwise::Scale
- Inherits:
-
Object
- Object
- Unitwise::Scale
- Includes:
- Compatible
- Defined in:
- lib/unitwise/scale.rb
Overview
A Unitwise::Scale represents a value and a unit, sort of like a vector, it has two components. In this case, it's a value and unit rather than a magnitude and direction. This class should be considered mostly privateish.
Direct Known Subclasses
Instance Method Summary collapse
-
#atoms ⇒ Array
List the atoms associated with this scale's unit.
-
#depth ⇒ Integer
How far away is this instances unit from the deepest leve atom.
-
#functional(x = value, forward = true) ⇒ Numeric
Return a converted value for this scale, based on it's function for scales with special units.
-
#initialize(*args) ⇒ Scale
constructor
A new instance of Scale.
- #inspect ⇒ Object
-
#root_terms ⇒ Array
The base units this scale's unit is derived from.
-
#scalar ⇒ Numeric
Return a scalar value for non-special units, this will be some ratio of a child base unit.
-
#special? ⇒ true, false
Is this scale's unit special?.
-
#terms ⇒ Array
List the terms associated with this scale's unit.
-
#to_s ⇒ Object
Convert to a simple string representing the scale.
-
#unit ⇒ Unitwise::Unit
The unit associated with this scale.
Methods included from Compatible
#<=>, #compatible_with?, #composition, #composition_string, #dim, included
Constructor Details
#initialize(*args) ⇒ Scale
Returns a new instance of Scale.
10 11 12 13 |
# File 'lib/unitwise/scale.rb', line 10 def initialize(*args) super(*args) freeze end |
Instance Method Details
#atoms ⇒ Array
List the atoms associated with this scale's unit.
25 26 27 |
# File 'lib/unitwise/scale.rb', line 25 def atoms unit.atoms end |
#depth ⇒ Integer
How far away is this instances unit from the deepest leve atom.
71 72 73 |
# File 'lib/unitwise/scale.rb', line 71 def depth unit.depth + 1 end |
#functional(x = value, forward = true) ⇒ Numeric
Return a converted value for this scale, based on it's function for scales with special units.
49 50 51 |
# File 'lib/unitwise/scale.rb', line 49 def functional(x=value, forward=true) unit.functional(x, forward) end |
#inspect ⇒ Object
81 82 83 |
# File 'lib/unitwise/scale.rb', line 81 def inspect "#<#{self.class} value=#{value} unit=#{unit}>" end |
#root_terms ⇒ Array
The base units this scale's unit is derived from
64 65 66 |
# File 'lib/unitwise/scale.rb', line 64 def root_terms unit.root_terms end |
#scalar ⇒ Numeric
Return a scalar value for non-special units, this will be some ratio of a child base unit.
57 58 59 |
# File 'lib/unitwise/scale.rb', line 57 def scalar value * unit.scalar end |
#special? ⇒ true, false
Is this scale's unit special?
39 40 41 |
# File 'lib/unitwise/scale.rb', line 39 def special? unit.special? end |
#terms ⇒ Array
List the terms associated with this scale's unit.
32 33 34 |
# File 'lib/unitwise/scale.rb', line 32 def terms unit.terms end |
#to_s ⇒ Object
Convert to a simple string representing the scale.
77 78 79 |
# File 'lib/unitwise/scale.rb', line 77 def to_s "#{value} #{unit}" end |
#unit ⇒ Unitwise::Unit
The unit associated with this scale.
18 19 20 |
# File 'lib/unitwise/scale.rb', line 18 def unit @unit.is_a?(Unit) ? @unit : Unit.new(@unit) end |