reservation 0.0.5 → 0.0.6

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.
@@ -24,6 +24,10 @@ module Reservation
24
24
  new HourMinute.parse(start), HourMinute.parse(finish)
25
25
  end
26
26
 
27
+ def self.parse intervals
28
+ intervals.split(',').map { |i| self.from(*i.split('-')) }
29
+ end
30
+
27
31
  def to_s
28
32
  "#{start}-#{finish}"
29
33
  end
@@ -1,3 +1,3 @@
1
1
  module Reservation
2
- VERSION = "0.0.5"
2
+ VERSION = "0.0.6"
3
3
  end
@@ -30,11 +30,18 @@ module Reservation
30
30
 
31
31
  patterns.each { |pattern|
32
32
  day = pattern["day"]
33
+ dayno = (day =~ /\d+/) ? day.to_i : DAY_MAP[day]
34
+
33
35
  nth_of_month = parse_nth_of_month pattern["nth_of_month"]
34
36
 
35
- start = HourMinute.parse pattern["start"]
36
- finish = HourMinute.parse pattern["finish"]
37
- self.wdays << Daily.new(DAY_MAP[day], nth_of_month, Interval.new(start, finish))
37
+ if pattern["intervals"]
38
+ intervals = Interval.parse(pattern["intervals"])
39
+ self.wdays.concat intervals.map { |i| Daily.new(dayno, nth_of_month, i) }
40
+ else
41
+ start = HourMinute.parse pattern["start"]
42
+ finish = HourMinute.parse pattern["finish"]
43
+ self.wdays << Daily.new(dayno, nth_of_month, Interval.new(start, finish))
44
+ end
38
45
  }
39
46
  end
40
47
 
@@ -34,4 +34,12 @@ describe Reservation::Schedule::Interval do
34
34
  event.start.pretty.should == "20130712T1830"
35
35
  event.finish.pretty.should == "20130712T2300"
36
36
  end
37
+
38
+ it "should parse a text list of intervals" do
39
+ intervals = Reservation::Schedule::Interval.parse "9h-12, 12h30-13:30 , 14-17.30"
40
+ intervals[0].to_s.should == "0900-1200"
41
+ intervals[1].to_s.should == "1230-1330"
42
+ intervals[2].to_s.should == "1400-1730"
43
+ intervals.size.should == 3
44
+ end
37
45
  end
@@ -28,6 +28,24 @@ describe Reservation::Schedule::Weekly do
28
28
  weekly.matches?(event).should be_true
29
29
  end
30
30
 
31
+ it "should match when there exists a matching interval on the same day as the given event and the day is given as numeric" do
32
+ weekly = Reservation::Schedule::Weekly.new [ { "day" => "3", "start" => "0930", "finish" => "10:30"},
33
+ { "day" => "3", "start" => "18", "finish" => "20" },
34
+ { "day" => "5", "start" => "7h", "finish" => "9:30" },
35
+ { "day" => "2", "start" => "7", "finish" => "8h30" } ]
36
+
37
+ weekly.matches?(event).should be_true
38
+ end
39
+
40
+ it "should match when there exists a matching interval on the same day as the given event and the day is given as numeric and intervals as a list" do
41
+ weekly = Reservation::Schedule::Weekly.new [ { "day" => "3", "intervals" => "7-830, 9h00-12:30,13-1730" },
42
+ { "day" => "3", "intervals" => "7-830, 9h00-12:30,13-1730" },
43
+ { "day" => "5", "intervals" => "9h00-12:30,7-930,13-1730 " },
44
+ { "day" => "2", "intervals" => "7-830, 9h00-12:30,13-1730" } ]
45
+
46
+ weekly.matches?(event).should be_true
47
+ end
48
+
31
49
  it "should not match when there exists no matching interval on the same day as the given event" do
32
50
  weekly = Reservation::Schedule::Weekly.new [ { "day" => "wed", "start" => "0930", "finish" => "10:30"},
33
51
  { "day" => "wed", "start" => "18", "finish" => "20" },
@@ -37,6 +55,15 @@ describe Reservation::Schedule::Weekly do
37
55
  weekly.matches?(event).should be_false
38
56
  end
39
57
 
58
+ it "should not match when there exists a matching interval on the same day as the given event and the day is given as numeric and intervals as a list" do
59
+ weekly = Reservation::Schedule::Weekly.new [ { "day" => "3", "intervals" => "7-830, 9h00-12:30,13-1730" },
60
+ { "day" => "3", "intervals" => "7-830, 9h00-12:30,13-1730" },
61
+ { "day" => "5", "intervals" => "9h00-12:30,7-1130,13-1730 " },
62
+ { "day" => "2", "intervals" => "7-830, 9h00-12:30,13-1730" } ]
63
+
64
+ weekly.matches?(event).should be_false
65
+ end
66
+
40
67
  it "should generate events corresponding to the weekly schedule" do
41
68
  weekly = Reservation::Schedule::Weekly.new [ { "day" => "wed", "start" => "0930", "finish" => "10:30"},
42
69
  { "day" => "wed", "start" => "18", "finish" => "20" },
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: reservation
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.6
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-01-21 00:00:00.000000000 Z
12
+ date: 2014-01-29 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails