Class: Insulin::Day
- Inherits:
-
Hash
- Object
- Hash
- Insulin::Day
- Defined in:
- lib/insulin/day.rb
Instance Attribute Summary collapse
-
#date ⇒ Object
readonly
Returns the value of attribute date.
-
#day ⇒ Object
readonly
Returns the value of attribute day.
-
#glucose_units ⇒ Object
readonly
Returns the value of attribute glucose_units.
Instance Method Summary collapse
- #average_glucose ⇒ Object
- #has_events? ⇒ Boolean
-
#initialize(date, mongo) ⇒ Day
constructor
A new instance of Day.
- #minimal ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(date, mongo) ⇒ Day
Returns a new instance of Day.
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/insulin/day.rb', line 7 def initialize date, mongo @date = date @mongo = mongo keys = [ "type", "subtype", "tag" ] self["all"] = [] @mongo.db.collection(date).find().each do |e| ev = Event.new(e) keys.each do |k| sub = ev[k] if self[sub] self[sub] << ev else self[sub] = [ev] end end self["all"] << ev @day = self["all"][0]["day"] end end |
Instance Attribute Details
#date ⇒ Object (readonly)
Returns the value of attribute date.
5 6 7 |
# File 'lib/insulin/day.rb', line 5 def date @date end |
#day ⇒ Object (readonly)
Returns the value of attribute day.
5 6 7 |
# File 'lib/insulin/day.rb', line 5 def day @day end |
#glucose_units ⇒ Object (readonly)
Returns the value of attribute glucose_units.
5 6 7 |
# File 'lib/insulin/day.rb', line 5 def glucose_units @glucose_units end |
Instance Method Details
#average_glucose ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/insulin/day.rb', line 42 def average_glucose t = 0 c = 0 begin self["glucose"].each do |g| @glucose_units = g["units"] t += g["value"] c += 1 end rescue NoMethodError return 0 end return t / c end |
#has_events? ⇒ Boolean
34 35 36 37 38 39 40 |
# File 'lib/insulin/day.rb', line 34 def has_events? if self["all"].size > 0 return true end return false end |
#minimal ⇒ Object
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 |
# File 'lib/insulin/day.rb', line 78 def minimal s = "" s << @date s << "\n" self["all"].each do |e| # if ["breakfast", "lunch", "dinner", "bedtime"].include? e["tag"] and # ["medication", "glucose"].include? e["type"] if e.simple? s << " " s << e.simple s << "\n" end end s end |
#to_s ⇒ Object
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/insulin/day.rb', line 58 def to_s s = "" s << @date s << "\n" self["all"].each do |e| s << " " s << e.simple s << "\n" end s << "\n" s << " " s << "average glucose: %4.2f %s" % [ self.average_glucose, @glucose_units ] s end |