Sha256: 5a4871db567fe934bbbc8fecb27769a89f929f5d7888027bbe8c7090187aba83

Contents?: true

Size: 1.13 KB

Versions: 11

Compression:

Stored size: 1.13 KB

Contents

module Insulin
# Author::  Sam (mailto:sam@cruft.co)
# License:: MIT

  module OnTrack

    # This class represents a single OnTrack CSV line
    class CsvLine < Hash

      # Parse the passed-in CSV line
      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
    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
insulin-0.1.11 lib/insulin/on_track/csv_line.rb
insulin-0.1.10 lib/insulin/on_track/csv_line.rb
insulin-0.1.9 lib/insulin/on_track/csv_line.rb
insulin-0.1.8 lib/insulin/on_track/csv_line.rb
insulin-0.1.7 lib/insulin/on_track/csv_line.rb
insulin-0.1.6 lib/insulin/on_track/csv_line.rb
insulin-0.1.5 lib/insulin/on_track/csv_line.rb
insulin-0.1.4 lib/insulin/on_track/csv_line.rb
insulin-0.1.3 lib/insulin/on_track/csv_line.rb
insulin-0.1.2 lib/insulin/on_track/csv_line.rb
insulin-0.1.1 lib/insulin/on_track/csv_line.rb