Class: Insulin::Week

Inherits:
Array
  • Object
show all
Defined in:
lib/insulin/week.rb

Instance Method Summary collapse

Constructor Details

#initialize(date, mongo) ⇒ Week

Returns a new instance of Week.



6
7
8
9
10
11
12
13
14
15
16
# File 'lib/insulin/week.rb', line 6

def initialize date, mongo
  @date = date
  @mongo = mongo

  t = Time.parse @date
  6.times do |i|
    d = (t + (i * 86400)).strftime "%F"
    day = Day.new d, @mongo
    self << day
  end
end

Instance Method Details

#average_glucoseObject



18
19
20
21
22
23
24
25
# File 'lib/insulin/week.rb', line 18

def average_glucose
  total = 0
  self.each do |d|
    total += d.average_glucose
  end

  return total / self.size
end

#to_sObject



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/insulin/week.rb', line 27

def to_s
  s = "Week commencing %s" % @date
  s << "\n"
  s << "\n"

  self.each do |d|
    s << d.minimal
    s << "\n"
  end

  s << "    "
  s << "Average glucose for week commencing %s: %4.1f" % [
    @date,
    self.average_glucose
  ]
  s
end