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.
-
#initialize(*args) ⇒ Scale
constructor
A new instance of Scale.
- #inspect ⇒ Object
-
#inverse_scalar(scalar = scalar) ⇒ Numeric
Get a magnitude based on a linear scale value.
-
#root_terms ⇒ Array
The base terms this scale's unit is derived from.
-
#scalar(magnitude = value) ⇒ Numeric
Get a scalar value for this scale.
-
#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.
81 82 83 |
# File 'lib/unitwise/scale.rb', line 81 def depth unit.depth + 1 end |
#inspect ⇒ Object
91 92 93 |
# File 'lib/unitwise/scale.rb', line 91 def inspect "#<#{self.class} value=#{value} unit=#{unit}>" end |
#inverse_scalar(scalar = scalar) ⇒ Numeric
Get a magnitude based on a linear scale value. Only used by scales with special atoms in it's hierarchy.
67 68 69 |
# File 'lib/unitwise/scale.rb', line 67 def inverse_scalar(scalar = scalar) unit.inverse_scalar(scalar) end |
#root_terms ⇒ Array
The base terms this scale's unit is derived from
74 75 76 |
# File 'lib/unitwise/scale.rb', line 74 def root_terms unit.root_terms end |
#scalar(magnitude = value) ⇒ Numeric
Get a scalar value for this scale.
54 55 56 57 58 59 60 |
# File 'lib/unitwise/scale.rb', line 54 def scalar(magnitude = value) if special? unit.scalar(magnitude) else value * unit.scalar end 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.
87 88 89 |
# File 'lib/unitwise/scale.rb', line 87 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 |