Class: Insulin::OnTrackCsvLine
- Inherits:
-
Hash
- Object
- Hash
- Insulin::OnTrackCsvLine
- Defined in:
- lib/insulin/on_track_csv_line.rb
Overview
This class represents a single OnTrack CSV line
Instance Method Summary collapse
-
#initialize(line) ⇒ OnTrackCsvLine
constructor
Parse the passed-in CSV line.
Constructor Details
#initialize(line) ⇒ OnTrackCsvLine
Parse the passed-in CSV line
9 10 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 |
# File 'lib/insulin/on_track_csv_line.rb', line 9 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 OnTrackDate.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::OnTrackNoteSet self["notes"] = OnTrackNoteSet.new notes if not notes == "" end |