insulin 0.0.14 → 0.0.15

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- insulin (0.0.13)
4
+ insulin (0.0.14)
5
5
  bson_ext
6
6
  ffi
7
7
  mongo
@@ -1,5 +1,5 @@
1
1
  module Insulin
2
2
 
3
3
  # Current version
4
- VERSION = "0.0.14"
4
+ VERSION = "0.0.15"
5
5
  end
@@ -0,0 +1,45 @@
1
+ require 'insulin'
2
+ require 'time'
3
+
4
+ module Insulin
5
+ class Week < Array
6
+ def initialize date, mongo
7
+ @date = date
8
+ @mongo = mongo
9
+
10
+ t = Time.parse @date
11
+ 6.times do |i|
12
+ d = (t + (i * 86400)).strftime "%F"
13
+ day = Day.new d, @mongo
14
+ self << day
15
+ end
16
+ end
17
+
18
+ def average_glucose
19
+ total = 0
20
+ self.each do |d|
21
+ total += d.average_glucose
22
+ end
23
+
24
+ return total / self.size
25
+ end
26
+
27
+ def to_s
28
+ s = "Week commencing %s" % @date
29
+ s << "\n"
30
+ s << "\n"
31
+
32
+ self.each do |d|
33
+ s << d.minimal
34
+ s << "\n"
35
+ end
36
+
37
+ s << " "
38
+ s << "Average glucose for week commencing %s: %4.1f" % [
39
+ @date,
40
+ self.average_glucose
41
+ ]
42
+ s
43
+ end
44
+ end
45
+ end
data/spec/week_spec.rb ADDED
@@ -0,0 +1,24 @@
1
+ require 'insulin'
2
+ require "spec_helper.rb"
3
+
4
+ describe Insulin::Week do
5
+ load_test_db
6
+
7
+ w = Insulin::Week.new "2012-06-29", @mongo
8
+
9
+ it "should contain something" do
10
+ w.size.should > 0
11
+ end
12
+
13
+ it "should have days" do
14
+ w.each do |d|
15
+ d.class.name.should == "Insulin::Day"
16
+ end
17
+ end
18
+
19
+ it "should have average glucose" do
20
+ w.average_glucose.should_not == nil
21
+ end
22
+
23
+ drop_test_db
24
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: insulin
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.14
4
+ version: 0.0.15
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -174,6 +174,7 @@ files:
174
174
  - lib/insulin/on_track/note.rb
175
175
  - lib/insulin/on_track/note_set.rb
176
176
  - lib/insulin/version.rb
177
+ - lib/insulin/week.rb
177
178
  - scripts/build.sh
178
179
  - spec/config_spec.rb
179
180
  - spec/day_spec.rb
@@ -185,6 +186,7 @@ files:
185
186
  - spec/on_track/note_set_spec.rb
186
187
  - spec/on_track/note_spec.rb
187
188
  - spec/spec_helper.rb
189
+ - spec/week_spec.rb
188
190
  homepage: http://pikesley.github.com/insulin/
189
191
  licenses: []
190
192
  post_install_message:
@@ -220,3 +222,4 @@ test_files:
220
222
  - spec/on_track/note_set_spec.rb
221
223
  - spec/on_track/note_spec.rb
222
224
  - spec/spec_helper.rb
225
+ - spec/week_spec.rb