timespan 0.4.9 → 0.5.0
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.
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.5.0
|
@@ -3,6 +3,40 @@ module Mongoid
|
|
3
3
|
extend ActiveSupport::Concern
|
4
4
|
|
5
5
|
module ClassMethods
|
6
|
+
attr_writer :max_asap, :min_asap
|
7
|
+
|
8
|
+
def max_asap time = nil
|
9
|
+
@max_asap ||= (time || 10.days.from_now).to_i
|
10
|
+
end
|
11
|
+
|
12
|
+
def min_asap time = nil
|
13
|
+
@min_asap ||= (time || 1.day.ago).to_i
|
14
|
+
end
|
15
|
+
|
16
|
+
def asap_method path
|
17
|
+
define_singleton_method :asap do
|
18
|
+
{:"#{path}.from".gte => min_asap, :"#{path}.from".lte => max_asap}
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def duration_methods path
|
23
|
+
define_singleton_method :exactly do |period|
|
24
|
+
[{:"#{path}.from" => period.to_i}, {:"#{path}.to" => period.to_i}]
|
25
|
+
end
|
26
|
+
|
27
|
+
define_singleton_method :in_between do |range|
|
28
|
+
[{:"#{path}.from" => range.min.to_i}, {:"#{path}.to" => range.max.to_i}]
|
29
|
+
end
|
30
|
+
|
31
|
+
define_singleton_method :at_least do |period|
|
32
|
+
{:"#{path}.to".gte => period.to_i }
|
33
|
+
end
|
34
|
+
|
35
|
+
define_singleton_method :at_most do |period|
|
36
|
+
{:"#{path}.to".lte => period.to_i }
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
6
40
|
# fx Account.timespan_container_delegates :period, :dates, :start, :end
|
7
41
|
# start_date= -> period.dates_start=
|
8
42
|
# end_date= -> period.dates_end=
|
@@ -54,35 +54,11 @@ describe TimeSpan do
|
|
54
54
|
time_period: TimePeriod.new(flex: (3..6).minutes)
|
55
55
|
end
|
56
56
|
|
57
|
-
def yesterday
|
58
|
-
1.day.ago.to_i
|
59
|
-
end
|
60
|
-
|
61
|
-
def where_hash
|
62
|
-
{:'period.from'.gte => yesterday, :'period.from'.lte => max_asap}
|
63
|
-
end
|
64
|
-
|
65
|
-
def exactly
|
66
|
-
[{:'time_period.flex.from' => period}, {:'time_period.flex.to' => period}]
|
67
|
-
end
|
68
|
-
|
69
|
-
def in_between
|
70
|
-
[{:'time_period.flex.from' => min_period}, {:'time_period.flex.to' => max_period}]
|
71
|
-
end
|
72
|
-
|
73
|
-
def at_least type = :min
|
74
|
-
{:'time_period.flex.to'.gte => send("#{type}_period") }
|
75
|
-
end
|
76
|
-
|
77
|
-
def at_most type = :max
|
78
|
-
{:'time_period.flex.to'.lte => send("#{type}_period") }
|
79
|
-
end
|
80
|
-
|
81
57
|
describe 'ASAP 2 minutes' do
|
82
58
|
let(:period) { 2.minutes.to_i }
|
83
59
|
|
84
60
|
let(:criteria) do
|
85
|
-
Account.where(
|
61
|
+
Account.where(TimePeriod.asap).or(TimePeriod.exactly period)
|
86
62
|
end
|
87
63
|
|
88
64
|
# it 'should have a nice criteria' do
|
@@ -90,6 +66,14 @@ describe TimeSpan do
|
|
90
66
|
# criteria.selector["period.from"].should be_a Hash
|
91
67
|
# end
|
92
68
|
|
69
|
+
it 'should have custom max_asap' do
|
70
|
+
TimePeriod.max_asap.should == 14.days.from_now.to_i
|
71
|
+
end
|
72
|
+
|
73
|
+
it 'should have custom min_asap' do
|
74
|
+
TimePeriod.min_asap.should == 2.days.ago.to_i
|
75
|
+
end
|
76
|
+
|
93
77
|
it 'should find #1, #2, #3, #4, #5' do
|
94
78
|
criteria.to_a.map(&:name).should include '1', '2', '5', '7'
|
95
79
|
end
|
@@ -107,7 +91,7 @@ describe TimeSpan do
|
|
107
91
|
let(:period) { 3.minutes.to_i }
|
108
92
|
|
109
93
|
let(:criteria) do
|
110
|
-
Account.where(
|
94
|
+
Account.where(TimePeriod.asap).or(TimePeriod.exactly period)
|
111
95
|
end
|
112
96
|
|
113
97
|
it 'should find #4, #10' do
|
@@ -120,7 +104,7 @@ describe TimeSpan do
|
|
120
104
|
let(:period) { 4.minutes.to_i }
|
121
105
|
|
122
106
|
let(:criteria) do
|
123
|
-
Account.where(
|
107
|
+
Account.where(TimePeriod.asap).or(TimePeriod.exactly period)
|
124
108
|
end
|
125
109
|
|
126
110
|
it 'should find #2, #3' do
|
@@ -129,11 +113,10 @@ describe TimeSpan do
|
|
129
113
|
end
|
130
114
|
|
131
115
|
describe 'ASAP 1-4 minutes' do
|
132
|
-
let(:
|
133
|
-
let(:max_period) { 4.minutes }
|
116
|
+
let(:period) { 1.minute..4.minutes }
|
134
117
|
|
135
118
|
let(:criteria) do
|
136
|
-
Account.where(
|
119
|
+
Account.where(TimePeriod.asap).or(TimePeriod.in_between period)
|
137
120
|
end
|
138
121
|
|
139
122
|
it 'should find #2, #3' do
|
@@ -146,8 +129,7 @@ describe TimeSpan do
|
|
146
129
|
end
|
147
130
|
|
148
131
|
describe 'ASAP 3-5 minutes' do
|
149
|
-
let(:
|
150
|
-
let(:max_period) { 5.minutes }
|
132
|
+
let(:period) { 3.minutes..5.minutes }
|
151
133
|
|
152
134
|
it 'should have a nice criteria' do
|
153
135
|
# puts "ASAP 3-5 minutes"
|
@@ -158,7 +140,7 @@ describe TimeSpan do
|
|
158
140
|
end
|
159
141
|
|
160
142
|
let(:criteria) do
|
161
|
-
Account.where(
|
143
|
+
Account.where(TimePeriod.asap).or(TimePeriod.in_between period)
|
162
144
|
end
|
163
145
|
|
164
146
|
it 'should find #2, #3' do
|
@@ -169,11 +151,10 @@ describe TimeSpan do
|
|
169
151
|
end
|
170
152
|
|
171
153
|
describe 'ASAP 5-7 minutes' do
|
172
|
-
let(:
|
173
|
-
let(:max_period) { 7.minutes }
|
154
|
+
let(:period) { 5.minutes..7.minutes }
|
174
155
|
|
175
156
|
let(:criteria) do
|
176
|
-
Account.where(
|
157
|
+
Account.where(TimePeriod.asap).or(TimePeriod.in_between period)
|
177
158
|
end
|
178
159
|
|
179
160
|
it 'should find #2, #3' do
|
@@ -184,10 +165,10 @@ describe TimeSpan do
|
|
184
165
|
end
|
185
166
|
|
186
167
|
describe 'ASAP at least 4 minutes' do
|
187
|
-
let(:
|
168
|
+
let(:period) { 4.minutes }
|
188
169
|
|
189
170
|
let(:criteria) do
|
190
|
-
Account.where
|
171
|
+
Account.where TimePeriod.asap.merge(TimePeriod.at_least period)
|
191
172
|
end
|
192
173
|
|
193
174
|
it 'should find #2, #3' do
|
@@ -199,10 +180,10 @@ describe TimeSpan do
|
|
199
180
|
end
|
200
181
|
|
201
182
|
describe 'ASAP at most 3 minutes' do
|
202
|
-
let(:
|
183
|
+
let(:period) { 3.minutes }
|
203
184
|
|
204
185
|
let(:criteria) do
|
205
|
-
Account.where
|
186
|
+
Account.where TimePeriod.asap.merge(TimePeriod.at_most period)
|
206
187
|
end
|
207
188
|
|
208
189
|
it 'should find #2, #3' do
|
data/timespan.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = "timespan"
|
8
|
-
s.version = "0.
|
8
|
+
s.version = "0.5.0"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Kristian Mandrup"]
|
12
|
-
s.date = "2012-09-
|
12
|
+
s.date = "2012-09-26"
|
13
13
|
s.description = "Makes it easy to calculate time distance in different units"
|
14
14
|
s.email = "kmandrup@gmail.com"
|
15
15
|
s.extra_rdoc_files = [
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: timespan
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.0
|
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: 2012-09-
|
12
|
+
date: 2012-09-26 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: chronic
|
@@ -302,7 +302,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
302
302
|
version: '0'
|
303
303
|
segments:
|
304
304
|
- 0
|
305
|
-
hash:
|
305
|
+
hash: 3316997137060640016
|
306
306
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
307
307
|
none: false
|
308
308
|
requirements:
|