Class: Jeti::Log::Entry

Inherits:
Object
  • Object
show all
Defined in:
lib/jeti/log/entry.rb

Direct Known Subclasses

Header

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(time, id, details) ⇒ Entry

Returns a new instance of Entry.



7
8
9
10
11
# File 'lib/jeti/log/entry.rb', line 7

def initialize(time, id, details)
  @time = time
  @id = id
  @details = details.each_slice(4).group_by(&:first)
end

Instance Attribute Details

#idObject (readonly)

Returns the value of attribute id.



5
6
7
# File 'lib/jeti/log/entry.rb', line 5

def id
  @id
end

Instance Method Details

#detail(sensor_id) ⇒ Object



17
18
19
20
21
# File 'lib/jeti/log/entry.rb', line 17

def detail(sensor_id)
  @details[sensor_id][0]
rescue
  nil
end

#timeObject



13
14
15
# File 'lib/jeti/log/entry.rb', line 13

def time
  @time.to_i
end

#value(sensor_id) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/jeti/log/entry.rb', line 23

def value(sensor_id)
  raw = detail(sensor_id)
  case raw[1]
  when '0','1','4','8'
    format_float(raw[2].to_i, raw[3].to_i)
  when '5'
    min = (raw[3].to_i & 0xFF00) >> 8
    sec = (raw[3].to_i & 0x00FF)
    (min * 60) + sec
  when '9'
    format_gps(raw[2].to_i, raw[3].to_i)
  when '14'
    format_date(raw[3])
  else
    nil
  end
rescue
  nil
end