Class: Insulin::OnTrack::CsvLine
- Inherits:
-
Hash
- Object
- Hash
- Insulin::OnTrack::CsvLine
- Defined in:
- lib/insulin/on_track/csv_line.rb
Overview
This class represents a single OnTrack CSV line
Instance Method Summary collapse
-
#initialize(line) ⇒ CsvLine
constructor
Parse the passed-in CSV line.
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 |
# 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 self["value"] = bits[6].to_f # 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 |