Class: Unitwise::Scale
Instance Attribute Summary collapse
Instance Method Summary
collapse
Methods included from Composable
#<=>, #composition, #composition_string, #dim, included, #similar_to?
Constructor Details
#initialize(value, unit) ⇒ Scale
Returns a new instance of Scale.
7
8
9
10
11
12
13
14
|
# File 'lib/unitwise/scale.rb', line 7
def initialize(value, unit)
@value = value
if unit.is_a?(Unit)
@unit = unit.dup
else
@unit = Unit.new(unit.to_s)
end
end
|
Instance Attribute Details
#value ⇒ Object
Returns the value of attribute value.
3
4
5
|
# File 'lib/unitwise/scale.rb', line 3
def value
@value
end
|
Instance Method Details
#atoms ⇒ Object
20
21
22
|
# File 'lib/unitwise/scale.rb', line 20
def atoms
unit.atoms
end
|
#depth ⇒ Object
48
49
50
|
# File 'lib/unitwise/scale.rb', line 48
def depth
unit.depth + 1
end
|
#dup ⇒ Object
16
17
18
|
# File 'lib/unitwise/scale.rb', line 16
def dup
self.class.new(value, unit)
end
|
#functional(x = value, direction = 1) ⇒ Object
32
33
34
|
# File 'lib/unitwise/scale.rb', line 32
def functional(x=value, direction=1)
unit.functional(x, direction)
end
|
#inspect ⇒ Object
60
61
62
|
# File 'lib/unitwise/scale.rb', line 60
def inspect
"<#{self.class} #{to_s}>"
end
|
#root_terms ⇒ Object
44
45
46
|
# File 'lib/unitwise/scale.rb', line 44
def root_terms
unit.root_terms
end
|
#scalar ⇒ Object
36
37
38
|
# File 'lib/unitwise/scale.rb', line 36
def scalar
value * unit.scalar
end
|
#special? ⇒ Boolean
28
29
30
|
# File 'lib/unitwise/scale.rb', line 28
def special?
unit.special?
end
|
#terminal? ⇒ Boolean
52
53
54
|
# File 'lib/unitwise/scale.rb', line 52
def terminal?
depth <= 3
end
|
#terms ⇒ Object
24
25
26
|
# File 'lib/unitwise/scale.rb', line 24
def terms
unit.terms
end
|
#to_s ⇒ Object
56
57
58
|
# File 'lib/unitwise/scale.rb', line 56
def to_s
"#{value} #{unit}"
end
|
#unit ⇒ Object
40
41
42
|
# File 'lib/unitwise/scale.rb', line 40
def unit
@unit ||= Unit.new(@unit_code)
end
|