datesplit 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. data/lib/datesplit.rb +6 -4
  2. data/spec/datesplit_spec.rb +6 -0
  3. metadata +7 -12
data/lib/datesplit.rb CHANGED
@@ -8,7 +8,7 @@ class Datesplit
8
8
  expressions.each do |expression, returns|
9
9
  m = @date_string.match(expression)
10
10
  if m
11
- @start_date = Date.parse("#{m.captures[returns.index(:month_only) || returns.index(:month_one)]} #{m.captures[returns.index(:day_one)]} #{m.captures[returns.index(:year)]}")
11
+ @start_date = Date.parse("#{m.captures[returns.index(:month_only) || returns.index(:month_one)]} #{m.captures[returns.index(:day_one)]} #{m.captures[returns.index(:year_only) || returns.index(:year_one)]}")
12
12
  break
13
13
  end
14
14
  end
@@ -20,7 +20,7 @@ class Datesplit
20
20
  expressions.each do |expression, returns|
21
21
  m = @date_string.match(expression)
22
22
  if m
23
- @end_date = Date.parse("#{m.captures[returns.index(:month_only) || returns.index(:month_two) ]} #{m.captures[returns.index(:day_two)]} #{m.captures[returns.index(:year)]}")
23
+ @end_date = Date.parse("#{m.captures[returns.index(:month_only) || returns.index(:month_two) ]} #{m.captures[returns.index(:day_two)]} #{m.captures[returns.index(:year_only) || returns.index(:year_two)]}")
24
24
  break
25
25
  end
26
26
  end
@@ -35,8 +35,10 @@ class Datesplit
35
35
  private
36
36
  def expressions
37
37
  {
38
- /(\w+)\.*(?:\t|\s)*(\d+)\w*(?:\t|\s)*(?:\-|to)(?:\t|\s)*(\d+)\w*,*(?:\t|\s)*(\d*)/ => [:month_only, :day_one, :day_two, :year], # September 13-15, 2011 (Year Optional)
39
- /(\w+)\.*(?:\t|\s)*(\d+)\w*(?:\t|\s)*(?:\-|to)(?:\t|\s)*(\w+)\.*(?:\t|\s)*(\d+)\w*,*(?:\t|\s)*(\d*)/ => [:month_one, :day_one, :month_two, :day_two, :year] # September 13 to October 15, 2011 (Year Optional)
38
+
39
+ /(\w+)\.*(?:\t|\s)*(\d+)\w*(?:\t|\s)*(?:\-|to)(?:\t|\s)*(\d+)\w*,*(?:\t|\s)*(\d*)/ => [:month_only, :day_one, :day_two, :year_only], # September 13-15, 2011 (Year Optional)
40
+ /(\w+)\.*(?:\t|\s)*(\d+)\w*(?:\t|\s)*(?:\-|to)(?:\t|\s)*(\w+)\.*(?:\t|\s)*(\d+)\w*,*(?:\t|\s)*(\d*)/ => [:month_one, :day_one, :month_two, :day_two, :year_only], # September 13 to October 15, 2011 (Year Optional)
41
+ /(\w+)\.*(?:\t|\s)*(\d{1,2})\w*,*(?:\t|\s)*(\d{4})(?:\t|\s)*(?:\-|to)(?:\t|\s)*(\w+)\.*(?:\t|\s)*(\d+)\w*,*(?:\t|\s)*(\d{4})/ => [:month_one, :day_one, :year_one, :month_two, :day_two, :year_two] # September 13, 2012 to October 15 2013 (Year Required)
40
42
  }
41
43
  end
42
44
  end
@@ -37,4 +37,10 @@ describe Datesplit do
37
37
  d.start_date.to_s.should == Date.parse('Apr 27 2012').to_s
38
38
  d.end_date.to_s.should == Date.parse('April 29, 2012').to_s
39
39
  end
40
+
41
+ it "should return dates for 'April 9, 2012 to January 1st 2013'" do
42
+ d = Datesplit.new('April 9, 2012 to January 1st 2013')
43
+ d.start_date.to_s.should == Date.parse('April 9 2012').to_s
44
+ d.end_date.to_s.should == Date.parse('January 1 2013').to_s
45
+ end
40
46
  end
metadata CHANGED
@@ -1,13 +1,12 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: datesplit
3
3
  version: !ruby/object:Gem::Version
4
- hash: 27
5
- prerelease:
4
+ prerelease: false
6
5
  segments:
7
6
  - 0
8
7
  - 0
9
- - 2
10
- version: 0.0.2
8
+ - 3
9
+ version: 0.0.3
11
10
  platform: ruby
12
11
  authors:
13
12
  - Sean Roberts
@@ -15,7 +14,8 @@ autorequire:
15
14
  bindir: bin
16
15
  cert_chain: []
17
16
 
18
- date: 2011-09-14 00:00:00 Z
17
+ date: 2011-09-14 00:00:00 -04:00
18
+ default_executable:
19
19
  dependencies: []
20
20
 
21
21
  description: Generate date objects from a date duration string (eg. 'September 9th-12th, 2012')
@@ -29,8 +29,7 @@ extra_rdoc_files: []
29
29
 
30
30
  files:
31
31
  - lib/datesplit.rb
32
- - spec/datesplit_spec.rb
33
- - spec/spec_helper.rb
32
+ has_rdoc: true
34
33
  homepage: http://github.com/seanroberts/datesplit
35
34
  licenses: []
36
35
 
@@ -40,27 +39,23 @@ rdoc_options: []
40
39
  require_paths:
41
40
  - lib
42
41
  required_ruby_version: !ruby/object:Gem::Requirement
43
- none: false
44
42
  requirements:
45
43
  - - ">="
46
44
  - !ruby/object:Gem::Version
47
- hash: 3
48
45
  segments:
49
46
  - 0
50
47
  version: "0"
51
48
  required_rubygems_version: !ruby/object:Gem::Requirement
52
- none: false
53
49
  requirements:
54
50
  - - ">="
55
51
  - !ruby/object:Gem::Version
56
- hash: 3
57
52
  segments:
58
53
  - 0
59
54
  version: "0"
60
55
  requirements: []
61
56
 
62
57
  rubyforge_project:
63
- rubygems_version: 1.8.10
58
+ rubygems_version: 1.3.6
64
59
  signing_key:
65
60
  specification_version: 3
66
61
  summary: Generate date objects from a date duration string (eg. 'September 9th-12th, 2012')