Class: DmmUtil::RecordingMeasurement

Inherits:
Object
  • Object
show all
Defined in:
lib/dmm_util/recording_measurement.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attrs) ⇒ RecordingMeasurement

Returns a new instance of RecordingMeasurement.



8
9
10
# File 'lib/dmm_util/recording_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



50
51
52
53
54
55
56
57
58
# File 'lib/dmm_util/recording_measurement.rb', line 50

def method_missing(meth, *args)
  if raw[:readings].has_key?(meth.to_s.upcase)
     Reading.new(raw[:readings][meth.to_s.upcase])
  elsif raw[:readings2].has_key?(meth.to_s.upcase)
    Reading.new(raw[:readings2][meth.to_s.upcase])
  else
    super
  end
end

Instance Attribute Details

#rawObject (readonly)

Returns the value of attribute raw.



6
7
8
# File 'lib/dmm_util/recording_measurement.rb', line 6

def raw
  @raw
end

Instance Method Details

#end_tsObject



16
17
18
# File 'lib/dmm_util/recording_measurement.rb', line 16

def end_ts
  raw[:end_ts]
end

#reading_namesObject



20
21
22
# File 'lib/dmm_util/recording_measurement.rb', line 20

def reading_names
  (raw[:readings].keys + raw[:readings2].keys).map{|r| r.downcase.to_sym}
end

#start_tsObject



12
13
14
# File 'lib/dmm_util/recording_measurement.rb', line 12

def start_ts 
  raw[:start_ts] 
end

#to_sObject



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/dmm_util/recording_measurement.rb', line 24

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