time_frame 0.0.1 → 0.0.2

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 45120e4f1dda9a59b63972c578060e6e94863907
4
- data.tar.gz: 60bea2d8848eeb0fd283bd8b7d484341944cae63
3
+ metadata.gz: 4b1557a07374e6920452eb537ce6fdaccfcc803e
4
+ data.tar.gz: 21f70e14bd56943add7fc321025cc23c0c662d2d
5
5
  SHA512:
6
- metadata.gz: 40e9e0a39e8a81cfe6b0c31c7d0124c7f5e8eb99a741af5d1ab1dd808e123b91afdac459801fa8de1ceb69c5c88f8e7eeea0b12a74f84e100510a0de8167914d
7
- data.tar.gz: 270624b7fdde20d0f3a37cc4be3b72a4189313554fc00d851fa56f0394d675849c2d60c0817a0ccdb4cddf89cd8f0f70c8c796f4dc59c10caf4e05e1728aaa9e
6
+ metadata.gz: 25975d48bc929e8d07a5a93bbc3f17c1eab3067b3c7b3a36d15a978f0df7baae5506f8d94b3dddd7060e4acf52accdf7974aa15f3632f688758d34bae7d95fbe
7
+ data.tar.gz: b2dfd3edaa44eec8a63a08b50befe96f11906b5bd8b4248ec333a4499f3312538f4ec4f65ab9f41ee515891d52ef938b7794262941f2d6fdf08c2842e15454b2
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- time_frame (0.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.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.1)
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.0)
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
- ## Description
4
-
5
- The time frame class provides an specialized and enhanced frame for time values.
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
- # => 2014-05-12 19:00:00 +0200..2014-05-12 19:10:00 +0200
78
- time_frame.without(other)
79
- # => [2014-05-12 00:00:00 +0200..2014-05-12 19:00:00 +0200, 2014-05-12 19:10:00 +0200..2014-05-13 00:00:00 +0200]
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
- # => 2014-05-12 19:15:00 +0200..2014-05-12 19:25:00 +0200
82
- # You can also use an array for substraction:
83
- time_frame.without(*[other, another])
84
- # => [2014-05-12 00:00:00 +0200..2014-05-12 19:00:00 +0200, 2014-05-12 19:10:00 +0200..2014-05-12 19:15:00 +0200, 2014-05-12 19:25:00 +0200..2014-05-13 00:00:00 +0200]
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.
@@ -1,6 +1,6 @@
1
1
  require 'active_support/core_ext'
2
2
 
3
- # avoid i18n deprecation warning
3
+ # Avoid i18n deprecation warning
4
4
  I18n.enforce_available_locales = false
5
5
 
6
6
  require 'time_frame/time_frame_splitter'
@@ -1,6 +1,6 @@
1
- # class that models a time frame
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
- module Splitter
5
- def split_by_interval(interval)
6
- time = @min
7
- max = @max
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
@@ -1,4 +1,4 @@
1
1
  # gem version
2
2
  class TimeFrame
3
- VERSION = '0.0.1'
3
+ VERSION = '0.0.2'
4
4
  end
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.1
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-14 00:00:00.000000000 Z
13
+ date: 2014-05-19 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: activesupport