Class: DexcomShareApi::Glucose
- Inherits:
-
Object
- Object
- DexcomShareApi::Glucose
- Defined in:
- lib/dexcom_share_api/glucose.rb
Instance Method Summary collapse
-
#initialize(raw_glucose_data) ⇒ Glucose
constructor
{ “WT”=>“Date(1709620791000)”, “ST”=>“Date(1709620791000)”, “DT”=>“Date(1709620791000-0500)”, “Value”=>164, “Trend”=>“Flat”, }.
- #inspect ⇒ Object
- #mgdl ⇒ Object
- #mmol ⇒ Object
-
#timestamp ⇒ Object
This is parsing out an epoch time from “Date(1709620791000)”.
- #to_h ⇒ Object
- #trend ⇒ Object
- #trend_arrow ⇒ Object
Constructor Details
#initialize(raw_glucose_data) ⇒ Glucose
"WT"=>"Date(1709620791000)",
"ST"=>"Date(1709620791000)",
"DT"=>"Date(1709620791000-0500)",
"Value"=>164,
"Trend"=>"Flat",
14 15 16 |
# File 'lib/dexcom_share_api/glucose.rb', line 14 def initialize(raw_glucose_data) @raw_glucose_data = raw_glucose_data end |
Instance Method Details
#inspect ⇒ Object
28 29 30 31 32 33 34 35 |
# File 'lib/dexcom_share_api/glucose.rb', line 28 def inspect out = "#<#{self.class}:#{object_id}" to_h.each do |key, value| out << " @#{key}=#{value}" end out << ">" out end |
#mgdl ⇒ Object
72 73 74 |
# File 'lib/dexcom_share_api/glucose.rb', line 72 def mgdl @raw_glucose_data["Value"].to_f end |
#mmol ⇒ Object
68 69 70 |
# File 'lib/dexcom_share_api/glucose.rb', line 68 def mmol mgdl_to_mmol(mgdl) end |
#timestamp ⇒ Object
This is parsing out an epoch time from “Date(1709620791000)”. It’s messy.
63 64 65 66 |
# File 'lib/dexcom_share_api/glucose.rb', line 63 def = @raw_glucose_data["ST"].match(/\d+/)[0] DateTime.strptime(, '%Q').iso8601 end |
#to_h ⇒ Object
18 19 20 21 22 23 24 25 26 |
# File 'lib/dexcom_share_api/glucose.rb', line 18 def to_h { trend:, trend_arrow:, timestamp:, mmol:, mgdl:, } end |
#trend ⇒ Object
37 38 39 |
# File 'lib/dexcom_share_api/glucose.rb', line 37 def trend @raw_glucose_data["Trend"].split(/(?=[A-Z])/).join("-").downcase end |
#trend_arrow ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/dexcom_share_api/glucose.rb', line 41 def trend_arrow case trend when "double-up" "↑↑" when "single-up" "↑" when "forty-five-up" "↗" when "flat" "→" when "forty-five-down" "↘" when "single-down" "↓" when "double-down" "↓↓" else raise StandardError, "Unhandled trend `#{trend}`. This is a bug!" end end |