artic 1.0.0 → 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/artic/time_range.rb +21 -21
- data/lib/artic/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f6d3493f33b4a7bda30633981f19e2dc57d127b4
|
4
|
+
data.tar.gz: ac48612706ed362f442ba3d10677cf80e2201b41
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f67b26be6c5d8b28d60a1a89553da7ae6144b6e0bd3e998b47fc0243cd0b2941967dc69e086d4829b57e72b84dcc0fdc4699b92a61b8ec580a04a47511231d44
|
7
|
+
data.tar.gz: b08d848f3a69a34ae826fe05247ee34030c1f1a10c9d5bdb180363b82f4f5d59f69d04c7d5d2169cb9e172cee48a56a69b79d9caded652bea7a11e81c4df3e30
|
data/lib/artic/time_range.rb
CHANGED
@@ -14,18 +14,18 @@ module Artic
|
|
14
14
|
#
|
15
15
|
# @return [TimeRange] the passed time range or a new time range
|
16
16
|
def build(range)
|
17
|
-
range.is_a?(TimeRange) ? range : TimeRange.new(range.
|
17
|
+
range.is_a?(TimeRange) ? range : TimeRange.new(range.begin, range.end)
|
18
18
|
end
|
19
19
|
end
|
20
20
|
|
21
21
|
# Initializes a new range.
|
22
22
|
#
|
23
|
-
# @param
|
24
|
-
# @param
|
23
|
+
# @param start_time [String] the start time (in HH:MM format)
|
24
|
+
# @param end_time [String] the end time (in HH:MM format)
|
25
25
|
#
|
26
26
|
# @raise [ArgumentError] if the start time or the end time is invalid
|
27
27
|
# @raise [ArgumentError] if the start time is after the end time
|
28
|
-
def initialize(
|
28
|
+
def initialize(start_time, end_time)
|
29
29
|
super
|
30
30
|
validate_range
|
31
31
|
end
|
@@ -37,7 +37,7 @@ module Artic
|
|
37
37
|
#
|
38
38
|
# @return [Boolean]
|
39
39
|
def overlaps?(other)
|
40
|
-
|
40
|
+
self.begin <= other.end && self.end >= other.begin
|
41
41
|
end
|
42
42
|
|
43
43
|
# Returns whether this range completely covers the one given.
|
@@ -46,7 +46,7 @@ module Artic
|
|
46
46
|
#
|
47
47
|
# @return [Boolean]
|
48
48
|
def covers?(other)
|
49
|
-
|
49
|
+
self.begin <= other.begin && self.end >= other.end
|
50
50
|
end
|
51
51
|
|
52
52
|
# Returns a range of +DateTime+ objects for this time range.
|
@@ -56,8 +56,8 @@ module Artic
|
|
56
56
|
# @return [Range]
|
57
57
|
def with_date(date)
|
58
58
|
Range.new(
|
59
|
-
DateTime.parse("#{date} #{
|
60
|
-
DateTime.parse("#{date} #{
|
59
|
+
DateTime.parse("#{date} #{self.begin}"),
|
60
|
+
DateTime.parse("#{date} #{self.end}")
|
61
61
|
)
|
62
62
|
end
|
63
63
|
|
@@ -98,15 +98,15 @@ module Artic
|
|
98
98
|
return [other] unless overlaps?(other)
|
99
99
|
return [] if covers?(other)
|
100
100
|
|
101
|
-
if
|
102
|
-
[
|
103
|
-
elsif
|
101
|
+
if self.begin <= other.begin && self.end <= other.end
|
102
|
+
[self.end..other.end]
|
103
|
+
elsif self.begin >= other.begin && self.end <= other.end
|
104
104
|
[
|
105
|
-
(other.
|
106
|
-
(
|
105
|
+
(other.begin..self.begin),
|
106
|
+
(self.end..other.end)
|
107
107
|
]
|
108
|
-
elsif
|
109
|
-
[other.
|
108
|
+
elsif self.begin >= other.begin && self.end >= other.end
|
109
|
+
[other.begin..self.begin]
|
110
110
|
end
|
111
111
|
end
|
112
112
|
|
@@ -115,18 +115,18 @@ module Artic
|
|
115
115
|
def validate_range
|
116
116
|
fail(
|
117
117
|
ArgumentError,
|
118
|
-
"#{
|
119
|
-
) unless
|
118
|
+
"#{self.begin} is not a valid time"
|
119
|
+
) unless self.begin =~ TIME_REGEX
|
120
120
|
|
121
121
|
fail(
|
122
122
|
ArgumentError,
|
123
|
-
"#{
|
124
|
-
) unless
|
123
|
+
"#{self.end} is not a valid time"
|
124
|
+
) unless self.end =~ TIME_REGEX
|
125
125
|
|
126
126
|
fail(
|
127
127
|
ArgumentError,
|
128
|
-
"#{
|
129
|
-
) if
|
128
|
+
"#{self.begin} is greater than #{self.end}"
|
129
|
+
) if self.begin > self.end
|
130
130
|
end
|
131
131
|
end
|
132
132
|
end
|
data/lib/artic/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: artic
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alessandro Desantis
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-10-
|
11
|
+
date: 2016-10-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: tzinfo
|