Class: Unitwise::Atom
Instance Attribute Summary collapse
Attributes inherited from Base
#names, #primary_code, #scale, #secondary_code, #symbol
Class Method Summary
collapse
Instance Method Summary
collapse
Methods included from Composable
#<=>, #composition, #composition_string, included, #similar_to?
Methods inherited from Base
all, find, find_by, #initialize, #slugs
Constructor Details
This class inherits a constructor from Unitwise::Base
Instance Attribute Details
#arbitrary ⇒ Object
Returns the value of attribute arbitrary.
3
4
5
|
# File 'lib/unitwise/atom.rb', line 3
def arbitrary
@arbitrary
end
|
#classification ⇒ Object
Returns the value of attribute classification.
3
4
5
|
# File 'lib/unitwise/atom.rb', line 3
def classification
@classification
end
|
#dim ⇒ Object
50
51
52
|
# File 'lib/unitwise/atom.rb', line 50
def dim
terminal? ? @dim || property : composition_string
end
|
#metric ⇒ Object
Returns the value of attribute metric.
3
4
5
|
# File 'lib/unitwise/atom.rb', line 3
def metric
@metric
end
|
#property ⇒ Object
Returns the value of attribute property.
3
4
5
|
# File 'lib/unitwise/atom.rb', line 3
def property
@property
end
|
#special ⇒ Object
Returns the value of attribute special.
3
4
5
|
# File 'lib/unitwise/atom.rb', line 3
def special
@special
end
|
Class Method Details
.data ⇒ Object
9
10
11
|
# File 'lib/unitwise/atom.rb', line 9
def data
@data ||= data_files.reduce([]){|m,f| m += YAML::load File.open(f)}
end
|
.data_files ⇒ Object
13
14
15
|
# File 'lib/unitwise/atom.rb', line 13
def data_files
%w(base_unit derived_unit).map{|type| Unitwise.data_file type}
end
|
Instance Method Details
#arbitrary? ⇒ Boolean
38
39
40
|
# File 'lib/unitwise/atom.rb', line 38
def arbitrary?
!!arbitrary
end
|
#base? ⇒ Boolean
18
19
20
|
# File 'lib/unitwise/atom.rb', line 18
def base?
scale.nil? && !@dim.nil?
end
|
#depth ⇒ Object
42
43
44
|
# File 'lib/unitwise/atom.rb', line 42
def depth
base? ? 0 : scale.depth + 1
end
|
#derived? ⇒ Boolean
22
23
24
|
# File 'lib/unitwise/atom.rb', line 22
def derived?
!base?
end
|
#functional(x = scalar, direction = 1) ⇒ Object
66
67
68
|
# File 'lib/unitwise/atom.rb', line 66
def functional(x=scalar, direction=1)
scale.functional(x, direction)
end
|
#inspect ⇒ Object
78
79
80
|
# File 'lib/unitwise/atom.rb', line 78
def inspect
"<#{self.class} #{to_s}>"
end
|
#metric? ⇒ Boolean
26
27
28
|
# File 'lib/unitwise/atom.rb', line 26
def metric?
base? ? true : !!metric
end
|
#nonmetric? ⇒ Boolean
30
31
32
|
# File 'lib/unitwise/atom.rb', line 30
def nonmetric?
!metric?
end
|
#root_terms ⇒ Object
70
71
72
|
# File 'lib/unitwise/atom.rb', line 70
def root_terms
base? ? [Term.new(atom: self)] : scale.root_terms
end
|
#scalar ⇒ Object
62
63
64
|
# File 'lib/unitwise/atom.rb', line 62
def scalar
base? ? 1 : scale.scalar
end
|
#scale=(attrs) ⇒ Object
54
55
56
57
58
59
60
|
# File 'lib/unitwise/atom.rb', line 54
def scale=(attrs)
@scale = if attrs[:function_code]
Functional.new(attrs[:value], attrs[:unit_code], attrs[:function_code])
else
Scale.new(attrs[:value], attrs[:unit_code])
end
end
|
#special? ⇒ Boolean
34
35
36
|
# File 'lib/unitwise/atom.rb', line 34
def special?
!!special
end
|
#terminal? ⇒ Boolean
46
47
48
|
# File 'lib/unitwise/atom.rb', line 46
def terminal?
depth <= 3
end
|
#to_s ⇒ Object
74
75
76
|
# File 'lib/unitwise/atom.rb', line 74
def to_s
"#{primary_code} (#{names.join('|')})"
end
|