Class: Insulin::OnTrack::CsvLine

Inherits:
Hash
  • Object
show all
Defined in:
lib/insulin/on_track/csv_line.rb

Overview

This class represents a single OnTrack CSV line

Instance Method Summary collapse

Constructor Details

#initialize(line) ⇒ CsvLine

Parse the passed-in CSV line



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/insulin/on_track/csv_line.rb', line 11

def initialize line

  # Split on commas 
  bits = line.split ","
  self["serial"] = bits[0].to_i

  # OnTrack embeds commas in the dates of its CSVs. Duh 
  self.update Date.new "%s%s" % [
    bits[1],
    bits[2]
  ]
  self["type"] = bits[3].downcase
  self["subtype"] = bits[4].downcase if not bits[4] == ""
  self["tag"] = bits[5].downcase
  if self["type"] == "blood pressure"
    self["value"] = bits[6]
  else
    self["value"] = bits[6].to_f
  end

  # Notes get complicated. Everything from field 7 to the end will be part
  # of the notes
  notes = bits[7..-1]

  # We may have embedded commas
  notes = notes.join ","
  
  # Strip the trailing '\n'
  notes = notes[1..-2]

  # See Insulin::OnTrack::NoteSet
  self["notes"] = NoteSet.new notes if not notes == ""
end