class FreestyleLibre::ExportFileParseResult

Attributes

auto_measurements[R]
manual_measurements[R]
patient_id[R]
patient_name[R]

Public Class Methods

new(export_file_path) click to toggle source
# File lib/freestyle_libre/export_file_parse_results.rb, line 5
def initialize(export_file_path)
  @auto_measurements = []
  @manual_measurements = []
  @time_changes = []
  parse_file(export_file_path)
end

Private Instance Methods

insert_auto_measurement(tokens) click to toggle source
# File lib/freestyle_libre/export_file_parse_results.rb, line 47
def insert_auto_measurement(tokens)
  @auto_measurements << Record.new(id: tokens[0].to_i,
           date_time: DateTime.strptime("#{tokens[1]}", '%Y-%m-%d %H:%M'),
           first_sensor_reading: nil,
           sensor_runtime_minutes: nil,
           value: tokens[3].to_i,
           errored: false,
           error_code: "0")
end
insert_manual_measurement(tokens) click to toggle source
# File lib/freestyle_libre/export_file_parse_results.rb, line 57
def insert_manual_measurement(tokens)
  @manual_measurements << Record.new(id: tokens[0].to_i,
                                        type: "2",
                                        date_time: DateTime.strptime("#{tokens[1]}", '%Y-%m-%d %H:%M'),
                                        value: tokens[4].to_i
                                        #errored: false)
                                        )
end
insert_time_change(tokens) click to toggle source
# File lib/freestyle_libre/export_file_parse_results.rb, line 44
def insert_time_change(tokens)
end
parse_file(export_file_path) click to toggle source
# File lib/freestyle_libre/export_file_parse_results.rb, line 15
def parse_file(export_file_path)
  File.open(export_file_path, "r") do |f|
    @patient_name = f.readline.strip
    @patient_id = f.readline.strip[2..-1]
    @columns = f.readline.strip.split("\t")
    while !f.eof?
      parse_line(f.readline)
    end
  end
end
parse_line(line) click to toggle source
# File lib/freestyle_libre/export_file_parse_results.rb, line 26
def parse_line(line)
  tokens = line.split("\t")
  case tokens[2]
  when '0'
    insert_auto_measurement(tokens)
  when '1'
    insert_manual_measurement(tokens)
  when '4'
    # fast acting insulin
  when '5'
    # food non-numerid
  when '6'
    insert_time_change(tokens)
  else
    puts Hash[@columns.zip(tokens)]
  end
end