Class: DmmUtil::Measurement
- Inherits:
-
Object
- Object
- DmmUtil::Measurement
show all
- Defined in:
- lib/dmm_util/measurement.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
Returns a new instance of Measurement.
8
9
10
|
# File 'lib/dmm_util/measurement.rb', line 8
def initialize(attrs)
@raw = attrs
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(meth, *args) ⇒ Object
54
55
56
57
58
59
60
|
# File 'lib/dmm_util/measurement.rb', line 54
def method_missing(meth, *args)
if raw[:readings].has_key?(meth.to_s.upcase)
Reading.new(raw[:readings][meth.to_s.upcase])
else
super
end
end
|
Instance Attribute Details
#raw ⇒ Object
Returns the value of attribute raw.
6
7
8
|
# File 'lib/dmm_util/measurement.rb', line 6
def raw
@raw
end
|
Instance Method Details
#name ⇒ Object
12
13
14
|
# File 'lib/dmm_util/measurement.rb', line 12
def name
raw[:name] || raise("Not a named measurement")
end
|
#prim_function ⇒ Object
20
21
22
|
# File 'lib/dmm_util/measurement.rb', line 20
def prim_function
raw[:prim_function]
end
|
#reading_names ⇒ Object
24
25
26
|
# File 'lib/dmm_util/measurement.rb', line 24
def reading_names
raw[:readings].keys.map{|r| r.downcase.to_sym}
end
|
#to_s ⇒ Object
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
|
# File 'lib/dmm_util/measurement.rb', line 28
def to_s
order = [:primary, :maximum, :average, :minimum, :rel_reference,
:secondary,
:db_ref, :temp_offset,
:live, :rel_live]
existing = reading_names
res = []
existing.delete(:live) if existing.include?(:live) && self.live == self.primary
(order - [:primary]).each do |name|
next unless existing.include?(name)
res << "#{name}: #{self.send(name).to_s}"
end
(existing - order).each do |name|
res << "#{name}: #{self.send(name).to_s}"
end
if res.empty?
primary.to_s
else
"#{primary.to_s} (#{res.join(", ")})"
end
end
|
#ts ⇒ Object
16
17
18
|
# File 'lib/dmm_util/measurement.rb', line 16
def ts
raw[:ts] || self.primary.ts
end
|