timespan 0.2.4 → 0.2.5
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 +1 -1
- data/lib/timespan.rb +11 -5
- data/spec/timespan/printer_spec.rb +5 -2
- data/spec/timespan_spec.rb +13 -0
- data/timespan.gemspec +1 -1
- metadata +2 -2
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.2.
|
1
|
+
0.2.5
|
data/lib/timespan.rb
CHANGED
@@ -34,12 +34,15 @@ class Timespan
|
|
34
34
|
def initialize options = {}
|
35
35
|
@is_new = true
|
36
36
|
|
37
|
+
@init_options = options
|
38
|
+
validate! if options == {}
|
39
|
+
|
37
40
|
case options
|
38
41
|
when Numeric, Duration, String
|
39
42
|
options = {:duration => options}
|
40
43
|
end
|
41
44
|
|
42
|
-
configure options
|
45
|
+
configure! options
|
43
46
|
|
44
47
|
@is_new = false
|
45
48
|
end
|
@@ -89,11 +92,14 @@ class Timespan
|
|
89
92
|
|
90
93
|
protected
|
91
94
|
|
95
|
+
attr_reader :init_options
|
96
|
+
|
92
97
|
def first_from keys, options = {}
|
93
98
|
keys.select {|key| options[key] }.first
|
94
99
|
end
|
95
100
|
|
96
|
-
|
101
|
+
# uses init_options to configure
|
102
|
+
def configure! options = {}
|
97
103
|
from = options[first_from START_KEYS, options]
|
98
104
|
to = options[first_from END_KEYS, options]
|
99
105
|
dur = options[first_from DURATION_KEYS, options]
|
@@ -114,12 +120,12 @@ class Timespan
|
|
114
120
|
self.start_time = Time.now
|
115
121
|
end
|
116
122
|
|
117
|
-
def validate!
|
118
|
-
raise ArgumentError, "#{valid_requirement}, was: #{current_config}" unless valid?
|
123
|
+
def validate!
|
124
|
+
raise ArgumentError, "#{valid_requirement}, was: #{init_options.inspect} resulting in state: #{current_config}" unless valid?
|
119
125
|
end
|
120
126
|
|
121
127
|
def valid_requirement
|
122
|
-
"Timespan must take
|
128
|
+
"Timespan must take 1-2 of :start_time, :end_time or :duration or simply a duration as number of seconds or a string"
|
123
129
|
end
|
124
130
|
|
125
131
|
def current_config
|
@@ -16,9 +16,12 @@ describe Timespan::Span do
|
|
16
16
|
describe 'print in danish - multiple modes' do
|
17
17
|
let(:timespan) { Timespan.new :from => from, :to => to }
|
18
18
|
|
19
|
-
|
19
|
+
let(:today) { Date.today.strftime('%d %b %Y') }
|
20
|
+
let(:yesterday) { 1.day.ago.strftime('%d %b %Y') }
|
20
21
|
|
21
|
-
|
22
|
+
its(:to_s) { should == "fra #{yesterday} til #{today} der varer ialt 1 dag" }
|
23
|
+
|
24
|
+
specify { subject.to_s(:dates).should == "fra #{yesterday} til #{today}" }
|
22
25
|
specify { subject.to_s(:duration).should == '1 dag' }
|
23
26
|
end
|
24
27
|
end
|
data/spec/timespan_spec.rb
CHANGED
@@ -6,6 +6,19 @@ describe Timespan do
|
|
6
6
|
let(:from) { Chronic.parse("1 day ago") }
|
7
7
|
let(:to) { Time.now }
|
8
8
|
|
9
|
+
context 'Invalid params' do
|
10
|
+
describe 'error msg' do
|
11
|
+
specify do
|
12
|
+
expect { Timespan.new }.to raise_error(ArgumentError)
|
13
|
+
end
|
14
|
+
|
15
|
+
specify do
|
16
|
+
expect { Timespan.new(nil) }.to raise_error(ArgumentError)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
|
9
22
|
context '2 days duration (from now - default)' do
|
10
23
|
let(:timespan) { Timespan.new :duration => "2 days"}
|
11
24
|
|
data/timespan.gemspec
CHANGED
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.2.
|
4
|
+
version: 0.2.5
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -254,7 +254,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
254
254
|
version: '0'
|
255
255
|
segments:
|
256
256
|
- 0
|
257
|
-
hash: -
|
257
|
+
hash: -867346219046105956
|
258
258
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
259
259
|
none: false
|
260
260
|
requirements:
|