time_frame 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +4 -4
- data/README.md +41 -13
- data/lib/time_frame.rb +1 -1
- data/lib/time_frame/time_frame.rb +6 -2
- data/lib/time_frame/time_frame_splitter.rb +8 -4
- data/lib/time_frame/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: 4b1557a07374e6920452eb537ce6fdaccfcc803e
|
4
|
+
data.tar.gz: 21f70e14bd56943add7fc321025cc23c0c662d2d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 25975d48bc929e8d07a5a93bbc3f17c1eab3067b3c7b3a36d15a978f0df7baae5506f8d94b3dddd7060e4acf52accdf7974aa15f3632f688758d34bae7d95fbe
|
7
|
+
data.tar.gz: b2dfd3edaa44eec8a63a08b50befe96f11906b5bd8b4248ec333a4499f3312538f4ec4f65ab9f41ee515891d52ef938b7794262941f2d6fdf08c2842e15454b2
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
time_frame (0.0.
|
4
|
+
time_frame (0.0.2)
|
5
5
|
activesupport (~> 4.0)
|
6
6
|
|
7
7
|
GEM
|
@@ -28,7 +28,7 @@ GEM
|
|
28
28
|
httpclient (2.3.4.1)
|
29
29
|
i18n (0.6.9)
|
30
30
|
json (1.8.1)
|
31
|
-
minitest (5.3.
|
31
|
+
minitest (5.3.4)
|
32
32
|
multi_json (1.10.0)
|
33
33
|
multipart-post (2.0.0)
|
34
34
|
nesty (1.0.2)
|
@@ -40,7 +40,7 @@ GEM
|
|
40
40
|
rack-protection (1.5.3)
|
41
41
|
rack
|
42
42
|
rainbow (2.0.0)
|
43
|
-
rake (10.3.
|
43
|
+
rake (10.3.2)
|
44
44
|
rspec (2.14.1)
|
45
45
|
rspec-core (~> 2.14.0)
|
46
46
|
rspec-expectations (~> 2.14.0)
|
@@ -55,7 +55,7 @@ GEM
|
|
55
55
|
powerpack (~> 0.0.6)
|
56
56
|
rainbow (>= 1.99.1, < 3.0)
|
57
57
|
ruby-progressbar (~> 1.4)
|
58
|
-
ruby-progressbar (1.5.
|
58
|
+
ruby-progressbar (1.5.1)
|
59
59
|
simplecov (0.8.2)
|
60
60
|
docile (~> 1.1.0)
|
61
61
|
multi_json
|
data/README.md
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
# TimeFrame
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
3
|
+
[![Gem Version](https://badge.fury.io/rb/time_frame.svg)](http://badge.fury.io/rb/time_frame)
|
4
|
+
[![Dependency Status](https://gemnasium.com/injixo/time_frame.svg)](https://gemnasium.com/injixo/time_frame)
|
5
|
+
[![Code Climate](https://codeclimate.com/github/injixo/time_frame.png)](https://codeclimate.com/github/injixo/time_frame)
|
6
6
|
|
7
7
|
## Installation
|
8
8
|
|
@@ -25,6 +25,10 @@ time_frame = TimeFrame.new(min: Time.now, duration: 1.day)
|
|
25
25
|
Let's play around a bit:
|
26
26
|
|
27
27
|
```ruby
|
28
|
+
# Using pp in some samples to beautify output:
|
29
|
+
require 'pp'
|
30
|
+
# => true
|
31
|
+
|
28
32
|
# Create a time frame instance from today with duration of 1 day
|
29
33
|
time_frame = TimeFrame.new(min: Time.now, duration: 1.day)
|
30
34
|
# => 2014-05-07 14:58:47 +0200..2014-05-08 14:58:47 +0200
|
@@ -72,22 +76,21 @@ time_frame.overlaps?(other_frame)
|
|
72
76
|
|
73
77
|
# Time frame without another time frame:
|
74
78
|
time_frame = TimeFrame.new(min: Time.new(2014, 5, 12), duration: 1.day)
|
75
|
-
# => 2014-05-12 00:00:00 +0200..2014-05-13 00:00:00 +0200
|
76
79
|
other = TimeFrame.new(min: Time.new(2014, 5, 12, 19), duration: 10.minutes)
|
77
|
-
|
78
|
-
|
79
|
-
#
|
80
|
+
pp time_frame.without(other)
|
81
|
+
# [2014-05-12 00:00:00 +0200..2014-05-12 19:00:00 +0200,
|
82
|
+
# 2014-05-12 19:10:00 +0200..2014-05-13 00:00:00 +0200]
|
83
|
+
|
84
|
+
# You can also use without with many TimeFrame's:
|
80
85
|
another = other.shift_by(15.minutes)
|
81
|
-
|
82
|
-
#
|
83
|
-
|
84
|
-
#
|
86
|
+
pp time_frame.without(other, another)
|
87
|
+
# [2014-05-12 00:00:00 +0200..2014-05-12 19:00:00 +0200,
|
88
|
+
# 2014-05-12 19:10:00 +0200..2014-05-12 19:15:00 +0200,
|
89
|
+
# 2014-05-12 19:25:00 +0200..2014-05-13 00:00:00 +0200]
|
85
90
|
|
86
91
|
# Use of the mathematical &. The intersection is returned:
|
87
92
|
time_frame = TimeFrame.new(min: Time.new(2014), duration: 1.day)
|
88
|
-
# => 2014-01-01 00:00:00 +0100..2014-01-02 00:00:00 +0100
|
89
93
|
other_time_frame = time_frame.shift_by(12.hours)
|
90
|
-
# => 2014-01-01 12:00:00 +0100..2014-01-02 12:00:00 +0100
|
91
94
|
time_frame & other_time_frame
|
92
95
|
# => 2014-01-01 12:00:00 +0100..2014-01-02 00:00:00 +0100
|
93
96
|
|
@@ -118,3 +121,28 @@ end
|
|
118
121
|
|
119
122
|
## Does `TimeFrame` inherit from `Range`?
|
120
123
|
No. Ruby's `Range` class is multi-purpose, it can hold contiuous values (like floats), as well as discrete values (like integers) and behaves differently according to their type. Instance methods like `#each` or `#size` just don't make sense for time values, the same is true for all methods provided by the `Enumerable` mixin.
|
124
|
+
|
125
|
+
|
126
|
+
## License
|
127
|
+
|
128
|
+
The [MIT License](http://opensource.org/licenses/MIT) (MIT)
|
129
|
+
|
130
|
+
Copyright (c) 2014 [InVision](http://www.invision.de)
|
131
|
+
|
132
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
133
|
+
of this software and associated documentation files (the "Software"), to deal
|
134
|
+
in the Software without restriction, including without limitation the rights
|
135
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
136
|
+
copies of the Software, and to permit persons to whom the Software is
|
137
|
+
furnished to do so, subject to the following conditions:
|
138
|
+
|
139
|
+
The above copyright notice and this permission notice shall be included in
|
140
|
+
all copies or substantial portions of the Software.
|
141
|
+
|
142
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
143
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
144
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
145
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
146
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
147
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
148
|
+
THE SOFTWARE.
|
data/lib/time_frame.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
|
-
# class
|
1
|
+
# The time frame class provides an specialized and enhanced range for time
|
2
|
+
# values.
|
2
3
|
class TimeFrame
|
3
|
-
include Splitter
|
4
4
|
attr_reader :min, :max
|
5
5
|
|
6
6
|
def initialize(args)
|
@@ -84,6 +84,10 @@ class TimeFrame
|
|
84
84
|
end
|
85
85
|
end
|
86
86
|
|
87
|
+
def split_by_interval(interval)
|
88
|
+
Splitter.new(self).split_by interval
|
89
|
+
end
|
90
|
+
|
87
91
|
def self.covering_time_frame_for(time_frames)
|
88
92
|
CoveredFrame.new(time_frames).frame
|
89
93
|
end
|
@@ -1,10 +1,14 @@
|
|
1
1
|
class TimeFrame
|
2
2
|
# Provides a method to split a time frame by a given interval. It returns
|
3
3
|
# an array which contains the intervals as TimeFrame instances.
|
4
|
-
|
5
|
-
def
|
6
|
-
|
7
|
-
|
4
|
+
class Splitter
|
5
|
+
def initialize(time_frame)
|
6
|
+
@time_frame = time_frame
|
7
|
+
end
|
8
|
+
|
9
|
+
def split_by(interval)
|
10
|
+
time = @time_frame.min
|
11
|
+
max = @time_frame.max
|
8
12
|
time_frames = []
|
9
13
|
until time >= max
|
10
14
|
time_old = time
|
data/lib/time_frame/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: time_frame
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Patrick Derichs
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2014-05-
|
13
|
+
date: 2014-05-19 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: activesupport
|