timelord 0.0.4 → 0.0.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.
Files changed (4) hide show
  1. data/Rakefile +5 -6
  2. data/lib/timelord.rb +19 -19
  3. data/spec/timelord_spec.rb +4 -0
  4. metadata +4 -4
data/Rakefile CHANGED
@@ -3,21 +3,17 @@ require 'spec/rake/spectask'
3
3
  require 'rake/rdoctask'
4
4
  require 'rake/gempackagetask'
5
5
 
6
+ specification = Gem::Specification.load("timelord.gemspec")
7
+
6
8
  Spec::Rake::SpecTask.new do |t|
7
9
  t.spec_files = FileList['spec/**/*_spec.rb']
8
10
  end
9
11
 
10
- task :default => [:test]
11
- task :test => [:spec]
12
-
13
- specification = Gem::Specification.load("timelord.gemspec")
14
- desc 'Package gem'
15
12
  Rake::GemPackageTask.new(specification) do |package|
16
13
  package.need_zip = true
17
14
  package.need_tar = true
18
15
  end
19
16
 
20
- desc 'Generate documentation'
21
17
  Rake::RDocTask.new(:rdoc) do |rdoc|
22
18
  rdoc.rdoc_dir = 'doc'
23
19
  rdoc.title = 'Timelord'
@@ -25,3 +21,6 @@ Rake::RDocTask.new(:rdoc) do |rdoc|
25
21
  rdoc.rdoc_files.include('README*')
26
22
  rdoc.rdoc_files.include('lib/**/*.rb')
27
23
  end
24
+
25
+ task :default => [:test]
26
+ task :test => [:spec]
data/lib/timelord.rb CHANGED
@@ -18,49 +18,49 @@ class Timelord
18
18
  # For more examples, check out the spec[https://github.com/halogenandtoast/timelord/blob/master/spec/timelord_spec.rb]
19
19
  def self.parse(str, format = :international)
20
20
  today = Date.today
21
- if str =~ /(\d{4})\/(\d{1,2})\/(\d{1,2})/i
21
+ if str =~ /\b(\d{4})\/(\d{1,2})\/(\d{1,2})\b/i
22
22
  Date.civil($1.to_i, $2.to_i, $3.to_i)
23
- elsif str =~ /(\d{4})\-(\d{1,2})\-(\d{1,2})/i
23
+ elsif str =~ /\b(\d{4})\-(\d{1,2})\-(\d{1,2})\b/i
24
24
  Date.civil($1.to_i, $2.to_i, $3.to_i)
25
- elsif str =~ /(\d{1,2})\/(\d{1,2})\/(\d{2}(\d{2})?)/i
25
+ elsif str =~ /\b(\d{1,2})\/(\d{1,2})\/(\d{2}(\d{2})?)\b/i
26
26
  if format == :american
27
27
  Date.civil($3.to_i, $1.to_i, $2.to_i)
28
28
  else
29
29
  Date.civil($3.to_i, $2.to_i, $1.to_i)
30
30
  end
31
- elsif str =~ /(\d{1,2})\/(\d{1,2})/i
31
+ elsif str =~ /\b(\d{1,2})\/(\d{1,2})\b/i
32
32
  date = if format == :american
33
33
  Date.civil(today.year, $1.to_i, $2.to_i)
34
34
  else
35
35
  Date.civil(today.year, $2.to_i, $1.to_i)
36
36
  end
37
37
  set_to_future(date)
38
- elsif str =~ /(\d{1,2})\s+(#{SHORT_MATCHER})/i
38
+ elsif str =~ /\b(\d{1,2})\s+(#{SHORT_MATCHER})\b/i
39
39
  date = Date.civil(today.year, SHORT_MONTHS.index($2.downcase) + 1, $1.to_i)
40
40
  set_to_future(date)
41
- elsif str =~ /(#{SHORT_MATCHER})\s+(\d{1,2})/i
41
+ elsif str =~ /\b(#{SHORT_MATCHER})\s+(\d{1,2})\b/i
42
42
  date = Date.civil(today.year, SHORT_MONTHS.index($1.downcase) + 1, $2.to_i)
43
43
  set_to_future(date)
44
- elsif str =~ /(\d{1,2})(#{ORDINAL_MATCHER})/i
44
+ elsif str =~ /\b(\d{1,2})(#{ORDINAL_MATCHER})\b/i
45
45
  date = Date.civil(today.year, today.month, $1.to_i)
46
46
  set_to_future(date)
47
- elsif str =~/next (#{DAY_MATCHER})/i
47
+ elsif str =~/\bnext (#{DAY_MATCHER})\b/i
48
48
  expected_index = DAY_NAMES.index($1.downcase) || SHORT_DAY_NAMES.index($1.downcase)
49
49
  next_weekday(expected_index)
50
- elsif str =~/next tues/
51
- next_weekday(DAY_NAMES.index("tue"))
52
- elsif str =~/next (thur|thurs)/
53
- next_weekday(DAY_NAMES.index("tue"))
54
- elsif str =~/(#{DAY_MATCHER})/i
50
+ elsif str =~/\bnext tues\b/
51
+ next_weekday(DAY_NAMES.index("tuesday"))
52
+ elsif str =~/\bnext (thur|thurs)\b/
53
+ next_weekday(DAY_NAMES.index("thursday"))
54
+ elsif str =~/\b(#{DAY_MATCHER})\b/i
55
55
  expected_index = DAY_NAMES.index($1.downcase) || SHORT_DAY_NAMES.index($1.downcase)
56
56
  current_weekday(expected_index)
57
- elsif str =~/tues/
58
- current_weekday(DAY_NAMES.index("tue"))
59
- elsif str =~/(thur|thurs)/
60
- current_weekday(DAY_NAMES.index("tue"))
61
- elsif str =~ /(today|tod)/i
57
+ elsif str =~/\btues\b/
58
+ current_weekday(DAY_NAMES.index("tuesday"))
59
+ elsif str =~/\b(thur|thurs)\b/
60
+ current_weekday(DAY_NAMES.index("thursday"))
61
+ elsif str =~ /\b(today|tod)\b/i
62
62
  today
63
- elsif str =~ /(tomorrow|tom)/i
63
+ elsif str =~ /\b(tomorrow|tom)\b/i
64
64
  today + 1
65
65
  end
66
66
  end
@@ -28,6 +28,10 @@ describe Timelord, 'parse' do
28
28
  Timelord.parse("I need to do something tom.").should == tomorrow
29
29
  end
30
30
 
31
+ it "does not parse 'monster' as monday" do
32
+ Timelord.parse("Monster mash").should == nil
33
+ end
34
+
31
35
  it "parses '12 Dec'" do
32
36
  twelth_of_december = Date.civil(2010,12,12)
33
37
  Timelord.parse("On 12 Dec I need to do something.").should == twelth_of_december
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: timelord
3
3
  version: !ruby/object:Gem::Version
4
- hash: 23
4
+ hash: 21
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 4
10
- version: 0.0.4
9
+ - 5
10
+ version: 0.0.5
11
11
  platform: ruby
12
12
  authors:
13
13
  - Matthew Mongeau
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-02-16 00:00:00 -05:00
18
+ date: 2011-04-09 00:00:00 -04:00
19
19
  default_executable:
20
20
  dependencies: []
21
21