Class: Unitwise::Standard::DerivedUnit

Inherits:
Base
  • Object
show all
Defined in:
lib/unitwise/standard/derived_unit.rb

Instance Attribute Summary

Attributes inherited from Base

#attributes

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

all, hash, #initialize, #names, path, #primary_code, read, #secondary_code, #symbol, write

Methods included from Extras

#hash_to_markup

Constructor Details

This class inherits a constructor from Unitwise::Standard::Base

Class Method Details

.local_keyObject



8
9
10
# File 'lib/unitwise/standard/derived_unit.rb', line 8

def self.local_key
  "derived_unit"
end

.remote_keyObject



4
5
6
# File 'lib/unitwise/standard/derived_unit.rb', line 4

def self.remote_key
  "unit"
end

Instance Method Details

#arbitrary?Boolean

Returns:

  • (Boolean)


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

def arbitrary?
  attributes["@isArbitrary"] == 'yes'
end

#classificationObject



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

def classification
  attributes["@class"]
end

#functionObject



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

def function
  Function.new(attributes["value"]) if special?
end

#metric?Boolean

Returns:

  • (Boolean)


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

def metric?
  attributes["@isMetric"] == 'yes'
end

#propertyObject



12
13
14
# File 'lib/unitwise/standard/derived_unit.rb', line 12

def property
  attributes["property"].to_s
end

#scaleObject



16
17
18
# File 'lib/unitwise/standard/derived_unit.rb', line 16

def scale
  Scale.new(attributes["value"]) unless special?
end

#special?Boolean

Returns:

  • (Boolean)


32
33
34
# File 'lib/unitwise/standard/derived_unit.rb', line 32

def special?
  attributes["@isSpecial"] == 'yes'
end

#to_hashObject



40
41
42
43
44
45
46
# File 'lib/unitwise/standard/derived_unit.rb', line 40

def to_hash
  hash = super()
  hash[:scale] = (special? ? function.to_hash : scale.to_hash)
  hash.merge({:classification => classification,
              :property => property, :metric => metric?,
              :special => special?, :arbitrary => arbitrary?})
end