nuvaring 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 0c57d2a2c73e0dad8c46dd05b63f7d483a01baf1
4
+ data.tar.gz: 18491acb8f10071f0c8bd8272555c4e544781e87
5
+ SHA512:
6
+ metadata.gz: 240e8f2ecc5903779ae84f9f4de4c4126b597544a47b297d477d0fd60abc21436212d90bbd35880b11c754a1e7f428ebe2787b1338976719f842db27b1b0325d
7
+ data.tar.gz: eda8d3578bd9dea30d92cad8f102dc4aa0f06e3da6275ca1c510f68fcc1cacfb45cfaf4e42d7fe25afbc38f846ecd55270707c030aabadd9c7419cfe5d8c265c
File without changes
@@ -0,0 +1,24 @@
1
+ class NuvaringCalendar
2
+ def initialize(default_insertion_date,options={})
3
+ @default_insertion_date = default_insertion_date
4
+ @calculator = NuvaringCalendar::Calculator.new @default_insertion_date, options
5
+ end
6
+
7
+ def insertion_dates
8
+ @calculator.insertion_dates.map(&:to_s)
9
+ end
10
+
11
+ def removal_dates
12
+ @calculator.removal_dates.map(&:to_s)
13
+ end
14
+
15
+ def swap_dates
16
+ @calculator.swap_dates.map(&:to_s)
17
+ end
18
+
19
+ def timeline
20
+ @calculator.timeline
21
+ end
22
+ end
23
+
24
+ require 'nuvaring_calendar/calculator'
@@ -0,0 +1,77 @@
1
+ require 'date'
2
+ class NuvaringCalendar
3
+ class Calculator
4
+
5
+ # Returns an [Array] containing all future insertion dates
6
+ attr_reader :insertion_dates
7
+ # Returns an [Array] containing all future removal dates
8
+ attr_reader :removal_dates
9
+ # Returns an [Array] containing all future swap dates
10
+ attr_reader :swap_dates
11
+
12
+ # @param default_insertion_date [Date || String] First date nuva ring was inserted
13
+ # @option options [Fixnum] :insertion_days Number of days to insert the nuva ring. Default 21.
14
+ # @option options [Fixnum] :wait_days Number of days to wait after removing the nuva ring. Default 7.
15
+ # @option options [Fixnum] :swap_times Number of times to keep replacing nuvaring with a new one before :wait_days. 1 swap time period == 1 x :insertion_days. Default 0.
16
+ # @option options [Fixnum] :limit For how many days into the future beyond default_insertion_date should we compute? Default 365.
17
+ def initialize(default_insertion_date, options={})
18
+ @default_insertion_date = parse_date default_insertion_date
19
+ @insertion_dates = []
20
+ @insertion_dates << @default_insertion_date
21
+ @removal_dates = []
22
+ @swap_dates = []
23
+ @insertion_days = options[:insertion_days] || 21
24
+ @wait_days = options[:wait_days] || 7
25
+ @limit = options[:limit] || 365
26
+ @swap_times = options[:swap_times] || 0
27
+ compute
28
+ end
29
+
30
+ def timeline
31
+ insertion_hash = Hash.new { |hash, key| hash[key] = :insert }
32
+ removal_hash = Hash.new { |hash, key| hash[key] = :remove }
33
+ swap_hash = Hash.new { |hash, key| hash[key] = :swap }
34
+
35
+ @insertion_dates.each do |d|
36
+ insertion_hash[d]
37
+ end
38
+ @removal_dates.each do |d|
39
+ removal_hash[d]
40
+ end
41
+ @swap_dates.each do |d|
42
+ swap_hash[d]
43
+ end
44
+ array = (((insertion_hash.merge(removal_hash).merge(swap_hash)).sort).map { |element| element.map { |inner_element| inner_element.to_s}})
45
+ Hash[array]
46
+ end
47
+
48
+ private
49
+
50
+ # calculates all future dates
51
+ def compute
52
+ current_date = @default_insertion_date
53
+ max = current_date + @limit - @insertion_days
54
+ begin
55
+ current_date += @insertion_days
56
+ @swap_times.times do
57
+ @swap_dates << current_date
58
+ current_date += @insertion_days
59
+ end
60
+ @removal_dates << current_date
61
+ current_date += @wait_days
62
+ @insertion_dates << current_date
63
+ end while current_date <= max
64
+ end
65
+
66
+ def parse_date(date)
67
+ if date.is_a? Date
68
+ date
69
+ elsif date.is_a? String
70
+ Date.parse date
71
+ else
72
+ raise "Invalid insertion date, expecting Date or String"
73
+ end
74
+ end
75
+
76
+ end
77
+ end
@@ -0,0 +1,3 @@
1
+ module NuvaringCalendar
2
+ VERSION="0.2.0"
3
+ end
metadata ADDED
@@ -0,0 +1,62 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: nuvaring
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.0
5
+ platform: ruby
6
+ authors:
7
+ - Wale Olaleye
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-04-13 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: minitest
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '5.5'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '5.5'
27
+ description: Provides insertion and removal dates for nuvaring birth control.
28
+ email:
29
+ executables: []
30
+ extensions: []
31
+ extra_rdoc_files: []
32
+ files:
33
+ - README.md
34
+ - lib/nuvaring_calendar.rb
35
+ - lib/nuvaring_calendar/calculator.rb
36
+ - lib/nuvaring_calendar/version.rb
37
+ homepage: https://github.com/waleo/nuvaring
38
+ licenses:
39
+ - MIT
40
+ metadata: {}
41
+ post_install_message:
42
+ rdoc_options: []
43
+ require_paths:
44
+ - lib
45
+ required_ruby_version: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - ">="
48
+ - !ruby/object:Gem::Version
49
+ version: '0'
50
+ required_rubygems_version: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ requirements: []
56
+ rubyforge_project:
57
+ rubygems_version: 2.2.2
58
+ signing_key:
59
+ specification_version: 4
60
+ summary: Nuvaring Planning Calendar
61
+ test_files: []
62
+ has_rdoc: