timeframe 0.0.5 → 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.5
1
+ 0.0.6
data/lib/timeframe.rb CHANGED
@@ -247,8 +247,10 @@ class Timeframe
247
247
  self.class.new((from - 1.year), (to - 1.year))
248
248
  end
249
249
 
250
- def to_json(*) # :nodoc:
251
- { :from => from, :to => to }.to_json
250
+ # Just a string that can be processed by Timeframe.interval... identical to #to_param
251
+ # accepts multiple arguments because of disagreements between active_support/json and json gem
252
+ def to_json(*)
253
+ to_param
252
254
  end
253
255
 
254
256
  # URL-friendly like "2008-10-25/2009-11-12"
@@ -293,11 +295,12 @@ class Timeframe
293
295
 
294
296
  # Construct a new Timeframe by parsing an ISO 8601 time interval string
295
297
  # http://en.wikipedia.org/wiki/ISO_8601#Time_intervals
296
- def interval(interval)
297
- raise ArgumentError, 'Intervals should be specified as a string' unless interval.is_a? String
298
- raise ArgumentError, 'Intervals should be specified according to ISO 8601, method 1, eliding times' unless interval =~ /^\d\d\d\d-\d\d-\d\d\/\d\d\d\d-\d\d-\d\d$/
298
+ def interval(str)
299
+ raise ArgumentError, 'Intervals should be specified as a string' unless str.is_a? String
300
+ raise ArgumentError, 'Intervals should be specified according to ISO 8601, method 1, eliding times' unless str =~ /^\d\d\d\d-\d\d-\d\d\/\d\d\d\d-\d\d-\d\d$/
299
301
 
300
- new(*interval.split('/').map { |date| Date.parse date })
302
+ new(*str.split('/').map { |date| Date.parse date })
301
303
  end
304
+ alias :from_json :interval
302
305
  end
303
306
  end
@@ -250,9 +250,16 @@ describe Timeframe do
250
250
  end
251
251
  end
252
252
 
253
+ describe 'Timeframe:class#from_json' do
254
+ it 'should understand its own #to_json' do
255
+ t = Timeframe.new(:year => 2009)
256
+ Timeframe.from_json(t.to_json).should == t
257
+ end
258
+ end
259
+
253
260
  describe '#to_json' do
254
261
  it 'should generate JSON' do
255
- Timeframe.new(:year => 2009).to_json.should == "{\"from\":\"2009-01-01\",\"to\":\"2010-01-01\"}"
262
+ Timeframe.new(:year => 2009).to_json.should == "2009-01-01/2010-01-01"
256
263
  end
257
264
  it 'should ignore any arguments you give it' do
258
265
  example = Timeframe.new(:year => 2009).to_json
data/timeframe.gemspec CHANGED
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{timeframe}
8
- s.version = "0.0.5"
8
+ s.version = "0.0.6"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Andy Rossmeissl", "Seamus Abshere", "Derek Kastner"]
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: timeframe
3
3
  version: !ruby/object:Gem::Version
4
- hash: 21
4
+ hash: 19
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 5
10
- version: 0.0.5
9
+ - 6
10
+ version: 0.0.6
11
11
  platform: ruby
12
12
  authors:
13
13
  - Andy Rossmeissl