Class: Unitwise::Scale

Inherits:
Object
  • Object
show all
Includes:
Composable
Defined in:
lib/unitwise/scale.rb

Direct Known Subclasses

Functional, Measurement

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

#valueObject (readonly)

Returns the value of attribute value.



3
4
5
# File 'lib/unitwise/scale.rb', line 3

def value
  @value
end

Instance Method Details

#atomsObject



20
21
22
# File 'lib/unitwise/scale.rb', line 20

def atoms
  unit.atoms
end

#depthObject



48
49
50
# File 'lib/unitwise/scale.rb', line 48

def depth
  unit.depth + 1
end

#dupObject



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

#inspectObject



60
61
62
# File 'lib/unitwise/scale.rb', line 60

def inspect
  "<#{self.class} #{to_s}>"
end

#root_termsObject



44
45
46
# File 'lib/unitwise/scale.rb', line 44

def root_terms
  unit.root_terms
end

#scalarObject



36
37
38
# File 'lib/unitwise/scale.rb', line 36

def scalar
  value * unit.scalar
end

#special?Boolean

Returns:

  • (Boolean)


28
29
30
# File 'lib/unitwise/scale.rb', line 28

def special?
  unit.special?
end

#terminal?Boolean

Returns:

  • (Boolean)


52
53
54
# File 'lib/unitwise/scale.rb', line 52

def terminal?
  depth <= 3
end

#termsObject



24
25
26
# File 'lib/unitwise/scale.rb', line 24

def terms
  unit.terms
end

#to_sObject



56
57
58
# File 'lib/unitwise/scale.rb', line 56

def to_s
  "#{value} #{unit}"
end

#unitObject



40
41
42
# File 'lib/unitwise/scale.rb', line 40

def unit
  @unit ||= Unit.new(@unit_code)
end