pickup_line 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 45c0eb9a7954a200098e20e7b3742feab020fe85
4
+ data.tar.gz: 961bacaf20e3f9bc0397bb80541cc1ff5dbbc3a7
5
+ SHA512:
6
+ metadata.gz: 3cf454320515e77ed6fd76e57bf66ea98e89eea0488c6f099455687929ff1bb5f2009c8bab01e0c33f3d12cda057ac5b8d68b47c92d6a446da68c5cc7a8f9423
7
+ data.tar.gz: 24a8ff904de8d9f78e66e8cf2fda0dfde1bfa4b7aab6419813aff078e751d540e5cc090532fea1f4e87bc7ab7eee80292f97bb3205908ec4f36746195df9b070
@@ -0,0 +1,53 @@
1
+ require 'date'
2
+
3
+ module PickupLine
4
+ class Parser
5
+
6
+ def initialize(date)
7
+ @date = date
8
+ end
9
+
10
+ def locate(str)
11
+ str = str.downcase
12
+ words = ['one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine', 'ten']
13
+ # Full month names
14
+ if str =~ /(#{Date::MONTHNAMES.compact.map(&:downcase).join('|')})(\s+\d+)?/
15
+ month_num = Date::MONTHNAMES.compact.map(&:downcase).index($1) + 1
16
+ day = $2 ? $2.to_i : -1
17
+ future_date day, month_num, @date.year
18
+ # Abbreviated month names
19
+ elsif str =~ /(#{Date::ABBR_MONTHNAMES.compact.map(&:downcase).join('|')})\.?(\s+\d+)?/
20
+ month_num = Date::ABBR_MONTHNAMES.compact.map(&:downcase).index($1) + 1
21
+ day = $2 ? $2.to_i : -1
22
+ future_date day, month_num, @date.year
23
+ # Day names
24
+ elsif str =~ /(#{Date::DAYNAMES.map(&:downcase).join('|')})/
25
+ dindex = Date::DAYNAMES.map(&:downcase).index $1
26
+ d = @date
27
+ d += 1 until d.wday == dindex
28
+ d
29
+ # In N days
30
+ elsif str =~ /in\s+(\d+)\s+days?/
31
+ @date + $1.to_i
32
+ # In N days (with words)
33
+ elsif str =~ /in\s+(#{words.join('|')})\s+days?/
34
+ days = words.index($1) + 1
35
+ @date + days
36
+ # Today
37
+ elsif str.include?('today')
38
+ @date
39
+ # Tomorrow
40
+ elsif str.include?('tomorrow')
41
+ @date + 1
42
+ end
43
+ end
44
+
45
+ private
46
+
47
+ def future_date(day, month, year = nil)
48
+ d = Date.new year, month, day
49
+ d < @date ? Date.new(year + 1, month, day) : d
50
+ end
51
+
52
+ end
53
+ end
@@ -0,0 +1,3 @@
1
+ module PickupLine
2
+ VERSION = '0.0.3'
3
+ end
@@ -0,0 +1,5 @@
1
+ module PickupLine
2
+
3
+ autoload :Parser, File.join(File.dirname(__FILE__), 'pickup_line/parser')
4
+
5
+ end
@@ -0,0 +1,13 @@
1
+ require_relative '../lib/pickup_line'
2
+
3
+ def thoughts(today, &block)
4
+ describe "on #{today}" do
5
+ block.call(Proc.new { |question, reference|
6
+ it "should see '#{question}' as #{reference}" do
7
+ d = PickupLine::Parser.new(today)
8
+ ref = d.locate question
9
+ ref.should == reference
10
+ end
11
+ })
12
+ end
13
+ end
metadata ADDED
@@ -0,0 +1,61 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: pickup_line
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.3
5
+ platform: ruby
6
+ authors:
7
+ - John Crepezzi
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-10-04 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rspec
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ description: Parsing dates out of short form updates
28
+ email: john.crepezzi@gmail.com
29
+ executables: []
30
+ extensions: []
31
+ extra_rdoc_files: []
32
+ files:
33
+ - lib/pickup_line/parser.rb
34
+ - lib/pickup_line/version.rb
35
+ - lib/pickup_line.rb
36
+ - spec/spec_helper.rb
37
+ homepage:
38
+ licenses: []
39
+ metadata: {}
40
+ post_install_message:
41
+ rdoc_options: []
42
+ require_paths:
43
+ - lib
44
+ required_ruby_version: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - '>='
47
+ - !ruby/object:Gem::Version
48
+ version: '0'
49
+ required_rubygems_version: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ requirements: []
55
+ rubyforge_project:
56
+ rubygems_version: 2.0.6
57
+ signing_key:
58
+ specification_version: 4
59
+ summary: Always gets a date
60
+ test_files:
61
+ - spec/spec_helper.rb