nickel 0.0.6 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +19 -0
- data/.travis.yml +8 -0
- data/.yardopts +1 -0
- data/CHANGELOG.md +7 -0
- data/Gemfile +3 -0
- data/License.txt +3 -1
- data/README.md +110 -0
- data/Rakefile +10 -18
- data/bin/run_specs.sh +14 -0
- data/lib/nickel.rb +4 -23
- data/lib/nickel/construct.rb +25 -28
- data/lib/nickel/construct_finder.rb +251 -244
- data/lib/nickel/construct_interpreter.rb +68 -69
- data/lib/nickel/nlp.rb +67 -31
- data/lib/nickel/{query.rb → nlp_query.rb} +160 -348
- data/lib/nickel/{query_constants.rb → nlp_query_constants.rb} +2 -6
- data/lib/nickel/occurrence.rb +48 -67
- data/lib/nickel/version.rb +3 -0
- data/lib/nickel/zdate.rb +244 -162
- data/lib/nickel/ztime.rb +152 -72
- data/nickel.gemspec +31 -38
- data/spec/lib/nickel/nlp_spec.rb +14 -0
- data/spec/lib/nickel/occurrence_spec.rb +40 -0
- data/spec/lib/nickel/zdate_spec.rb +94 -0
- data/spec/lib/nickel/ztime_spec.rb +331 -0
- data/spec/lib/nickel_spec.rb +1859 -0
- data/spec/spec_helper.rb +22 -0
- metadata +124 -35
- data/History.txt +0 -11
- data/README.rdoc +0 -69
- data/lib/nickel/instance_from_hash.rb +0 -13
- data/lib/nickel/ruby_ext/calling_method.rb +0 -10
- data/lib/nickel/ruby_ext/to_s2.rb +0 -12
- data/spec/nickel_spec.rb +0 -165
- data/test/compare.rb +0 -109
- data/test/nlp_test.rb +0 -813
- data/test/nlp_tests_helper.rb +0 -55
- data/test/zdate_test.rb +0 -44
- data/test/ztime_test.rb +0 -429
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: ba3e838fa5d6806f85eb03ddf6732481d5d09947
|
4
|
+
data.tar.gz: f1e5af3b3a1b16c2c9f5a67eedcdf479e37265c9
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 77c82d90eab894ed70b59e586bb8dab299e43fe2999d4d5e015f33dc133a8614bae437e4fbdf2f7aa75caccc721612123bb67fe778f07cb6dfa9fe82cbe783e7
|
7
|
+
data.tar.gz: e95c789fd5d6c6ec167690a0e199b19411620faf0427bf4e302a10ed95a44ab00b8dafc1d74475c3ad3b074496ae1c647780f374bc511d3a0e2af1272d6849d7
|
data/.gitignore
ADDED
data/.travis.yml
ADDED
data/.yardopts
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--markup markdown --title "Nickel"
|
data/CHANGELOG.md
ADDED
data/Gemfile
ADDED
data/License.txt
CHANGED
@@ -1,4 +1,6 @@
|
|
1
|
-
Copyright (c)
|
1
|
+
Copyright (c) 2008 Lou Zell, lzell11@gmail.com, http://hazelmade.com
|
2
|
+
|
3
|
+
MIT License
|
2
4
|
|
3
5
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
6
|
of this software and associated documentation files (the "Software"), to deal
|
data/README.md
ADDED
@@ -0,0 +1,110 @@
|
|
1
|
+
Nickel
|
2
|
+
======
|
3
|
+
|
4
|
+
Nickel extracts date, time, and message information from naturally worded text.
|
5
|
+
|
6
|
+
[![Gem Version](http://img.shields.io/gem/v/nickel.svg)](http://rubygems.org/gems/nickel)
|
7
|
+
[![Build Status](http://img.shields.io/travis/iainbeeston/nickel/master.svg)](https://travis-ci.org/iainbeeston/nickel)
|
8
|
+
[![Coverage Status](http://img.shields.io/coveralls/iainbeeston/nickel/master.svg)](https://coveralls.io/r/iainbeeston/nickel)
|
9
|
+
[![Code Climate](http://img.shields.io/codeclimate/github/iainbeeston/nickel.svg)](https://codeclimate.com/github/iainbeeston/nickel)
|
10
|
+
|
11
|
+
Install
|
12
|
+
-------
|
13
|
+
|
14
|
+
If you use bundler add `gem "nickel"` to your gemfile, or if not run `gem install nickel` from the command line.
|
15
|
+
|
16
|
+
Usage
|
17
|
+
-----
|
18
|
+
|
19
|
+
A single occurrence
|
20
|
+
|
21
|
+
~~~ ruby
|
22
|
+
n = Nickel.parse "use the force on july 1st at 9am"
|
23
|
+
n.message #=> "use the force"
|
24
|
+
n.occurrences.first.start_date #=> "20110701"
|
25
|
+
~~~
|
26
|
+
|
27
|
+
A daily occurrence
|
28
|
+
|
29
|
+
~~~ ruby
|
30
|
+
n = Nickel.parse "wake up everyday at 11am"
|
31
|
+
n.message # => wake up
|
32
|
+
n.occurrences[0].type # => daily
|
33
|
+
n.occurrences[0].start_time # => 11:00:00
|
34
|
+
~~~
|
35
|
+
|
36
|
+
A weekly occurrence
|
37
|
+
|
38
|
+
~~~ ruby
|
39
|
+
n = Nickel.parse "guitar lessons every tuesday at 5pm"
|
40
|
+
n.message # => guitar lessons
|
41
|
+
n.occurrences[0].type # => weekly
|
42
|
+
n.occurrences[0].day_of_week # => 1
|
43
|
+
n.occurrences[0].interval # => 1
|
44
|
+
n.occurrences[0].start_time # => 17:00:00
|
45
|
+
~~~
|
46
|
+
|
47
|
+
A day monthly occurrence
|
48
|
+
|
49
|
+
~~~ ruby
|
50
|
+
n = Nickel.parse "drink specials on the second thursday of every month"
|
51
|
+
n.message # => drink specials
|
52
|
+
n.occurrences[0].type # => daymonthly
|
53
|
+
n.occurrences[0].day_of_week # => 4
|
54
|
+
n.occurrences[0].week_of_month # => 2
|
55
|
+
n.occurrences[0].interval # => 1
|
56
|
+
~~~
|
57
|
+
|
58
|
+
A date monthly occurrence
|
59
|
+
|
60
|
+
~~~ ruby
|
61
|
+
n = Nickel.parse "pay credit card every month on the 22nd"
|
62
|
+
n.message # => pay credit card
|
63
|
+
n.occurrences[0].type # => datemonthly
|
64
|
+
n.occurrences[0].date_of_month # => 22
|
65
|
+
n.occurrences[0].interval # => 1
|
66
|
+
~~~
|
67
|
+
|
68
|
+
Multiple occurrences
|
69
|
+
|
70
|
+
~~~ ruby
|
71
|
+
n = Nickel.parse "band meeting every monday and wednesday at 2pm"
|
72
|
+
n.message # => band meeting
|
73
|
+
n.occurrences[0].type # => weekly
|
74
|
+
n.occurrences[0].day_of_week # => 0
|
75
|
+
n.occurrences[0].start_time # => 14:00:00
|
76
|
+
n.occurrences[1].type # => weekly
|
77
|
+
n.occurrences[1].day_of_week # => 2
|
78
|
+
n.occurrences[1].start_time # => 14:00:00
|
79
|
+
~~~
|
80
|
+
|
81
|
+
Occurrences without any message
|
82
|
+
|
83
|
+
~~~ ruby
|
84
|
+
n = Nickel.parse "a week from tomorrow"
|
85
|
+
n.occurrences[0].start_date # => 20140320
|
86
|
+
~~~
|
87
|
+
|
88
|
+
Setting current time
|
89
|
+
|
90
|
+
~~~ ruby
|
91
|
+
n = Nickel.parse "lunch 3 days from now", DateTime.new(2010,3,31)
|
92
|
+
n.message # => lunch
|
93
|
+
n.occurrences[0].start_date # => 20100403
|
94
|
+
~~~
|
95
|
+
|
96
|
+
Extracting ruby date and time objects
|
97
|
+
|
98
|
+
~~~ ruby
|
99
|
+
n = Nickel.parse "dinner with friends at 8:00pm tonight"
|
100
|
+
n.message # => dinner with friends
|
101
|
+
n.occurrences[0].start_date.to_date # => 2014-02-23
|
102
|
+
n.occurrences[0].start_time.to_time # => 2014-02-23 20:00:00 +0000
|
103
|
+
~~~
|
104
|
+
|
105
|
+
Credits
|
106
|
+
-------
|
107
|
+
|
108
|
+
Nickel was originally developed by [Lou Zell](https://github.com/lzell/nickel), but is now maintained by [Iain Beeston](https://github.com/iainbeeston/nickel).
|
109
|
+
|
110
|
+
Copyright (c) 2008-2013 Lou Zell, lzell11@gmail.com, http://hazelmade.com
|
data/Rakefile
CHANGED
@@ -1,22 +1,14 @@
|
|
1
1
|
require 'rake'
|
2
|
-
require '
|
3
|
-
require '
|
2
|
+
require 'bundler/gem_tasks'
|
3
|
+
require 'rspec/core/rake_task'
|
4
|
+
require 'coveralls/rake/task'
|
5
|
+
require 'yard'
|
4
6
|
|
5
|
-
|
6
|
-
task :default => :test
|
7
|
+
task default: :spec
|
7
8
|
|
8
|
-
|
9
|
-
Rake::TestTask.new(:test) do |t|
|
10
|
-
t.libs << 'lib'
|
11
|
-
t.pattern = 'test/**/*_test.rb'
|
12
|
-
t.verbose = true
|
13
|
-
end
|
9
|
+
RSpec::Core::RakeTask.new(:spec)
|
14
10
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
rdoc.options << '--line-numbers' << '--inline-source'
|
20
|
-
rdoc.rdoc_files.include('README.rdoc')
|
21
|
-
rdoc.rdoc_files.include('lib/**/*.rb')
|
22
|
-
end
|
11
|
+
YARD::Rake::YardocTask.new(:yard)
|
12
|
+
|
13
|
+
Coveralls::RakeTask.new
|
14
|
+
task test_with_coveralls: [:spec, 'coveralls:push']
|
data/bin/run_specs.sh
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/bin/bash
|
2
|
+
# Run specs individually, to avoid interdependencies.
|
3
|
+
# Based on scripts from github.com/rspec/rspec-expectations
|
4
|
+
|
5
|
+
function run_specs_one_by_one {
|
6
|
+
for file in `find spec -iname '*_spec.rb'`; do
|
7
|
+
echo "rspec $file"
|
8
|
+
rspec --backtrace $file
|
9
|
+
done
|
10
|
+
}
|
11
|
+
|
12
|
+
run_specs_one_by_one
|
13
|
+
|
14
|
+
COVERALLS=true rspec --warnings
|
data/lib/nickel.rb
CHANGED
@@ -1,30 +1,11 @@
|
|
1
|
-
# Ruby Nickel Library
|
2
|
-
# Copyright (c) 2008-2011 Lou Zell, lzell11@gmail.com, http://hazelmade.com
|
3
|
-
# MIT License [http://www.opensource.org/licenses/mit-license.php]
|
4
|
-
#
|
5
1
|
# Usage:
|
6
|
-
#
|
2
|
+
#
|
7
3
|
# Nickel.parse "some query", Time.local(2011, 7, 1)
|
8
4
|
#
|
9
5
|
# The second term is optional.
|
10
6
|
|
11
|
-
require '
|
12
|
-
require '
|
13
|
-
|
14
|
-
path = File.expand_path(File.join(File.dirname(__FILE__), 'nickel'))
|
15
|
-
|
16
|
-
require File.join(path, 'ruby_ext', 'to_s2.rb')
|
17
|
-
require File.join(path, 'ruby_ext', 'calling_method.rb')
|
18
|
-
require File.join(path, 'zdate.rb')
|
19
|
-
require File.join(path, 'ztime.rb')
|
20
|
-
require File.join(path, 'instance_from_hash')
|
21
|
-
require File.join(path, 'query_constants')
|
22
|
-
require File.join(path, 'query')
|
23
|
-
require File.join(path, 'construct')
|
24
|
-
require File.join(path, 'construct_finder')
|
25
|
-
require File.join(path, 'construct_interpreter')
|
26
|
-
require File.join(path, 'occurrence')
|
27
|
-
require File.join(path, 'nlp.rb')
|
7
|
+
require 'nickel/version'
|
8
|
+
require 'nickel/nlp'
|
28
9
|
|
29
10
|
module Nickel
|
30
11
|
class << self
|
@@ -33,5 +14,5 @@ module Nickel
|
|
33
14
|
n.parse
|
34
15
|
n
|
35
16
|
end
|
36
|
-
end
|
17
|
+
end
|
37
18
|
end
|
data/lib/nickel/construct.rb
CHANGED
@@ -1,18 +1,16 @@
|
|
1
|
-
# Ruby Nickel Library
|
2
|
-
# Copyright (c) 2008-2011 Lou Zell, lzell11@gmail.com, http://hazelmade.com
|
3
|
-
# MIT License [http://www.opensource.org/licenses/mit-license.php]
|
4
|
-
|
5
1
|
module Nickel
|
6
2
|
|
7
3
|
class Construct
|
8
|
-
include InstanceFromHash
|
9
4
|
attr_accessor :comp_start, :comp_end, :found_in
|
5
|
+
def initialize(h)
|
6
|
+
h.each { |k,v| send("#{k}=", v) }
|
7
|
+
end
|
10
8
|
end
|
11
9
|
|
12
10
|
class DateConstruct < Construct
|
13
11
|
attr_accessor :date
|
14
12
|
def interpret
|
15
|
-
{:date =>
|
13
|
+
{:date => date}
|
16
14
|
end
|
17
15
|
end
|
18
16
|
|
@@ -23,7 +21,7 @@ module Nickel
|
|
23
21
|
class TimeConstruct < Construct
|
24
22
|
attr_accessor :time
|
25
23
|
def interpret
|
26
|
-
{:time =>
|
24
|
+
{:time => time}
|
27
25
|
end
|
28
26
|
end
|
29
27
|
|
@@ -37,18 +35,17 @@ module Nickel
|
|
37
35
|
|
38
36
|
class RecurrenceConstruct < Construct
|
39
37
|
attr_accessor :repeats, :repeats_on
|
40
|
-
|
38
|
+
|
41
39
|
def interpret
|
42
40
|
if variant_of?(:daily) then interpret_daily_variant
|
43
41
|
elsif variant_of?(:weekly) then interpret_weekly_variant
|
44
42
|
elsif variant_of?(:daymonthly) then interpret_daymonthly_variant
|
45
43
|
elsif variant_of?(:datemonthly) then interpret_datemonthly_variant
|
46
44
|
else
|
47
|
-
|
48
|
-
raise StandardError.new("self is an invalid variant, check value of self.repeats or @repeats")
|
45
|
+
raise StandardError.new("self is an invalid variant, check value of self.repeats")
|
49
46
|
end
|
50
47
|
end
|
51
|
-
|
48
|
+
|
52
49
|
def get_interval
|
53
50
|
if has_interval_of?(1) then 1
|
54
51
|
elsif has_interval_of?(2) then 2
|
@@ -61,18 +58,18 @@ module Nickel
|
|
61
58
|
private
|
62
59
|
def has_interval_of?(x)
|
63
60
|
case x
|
64
|
-
when 1 then [:daily, :weekly, :daymonthly, :datemonthly].include?(
|
65
|
-
when 2 then [:altdaily, :altweekly, :altdaymonthly, :altdatemonthly].include?(
|
66
|
-
when 3 then [:threedaily, :threeweekly, :threedaymonthly, :threedatemonthly].include?(
|
61
|
+
when 1 then [:daily, :weekly, :daymonthly, :datemonthly].include?(repeats)
|
62
|
+
when 2 then [:altdaily, :altweekly, :altdaymonthly, :altdatemonthly].include?(repeats)
|
63
|
+
when 3 then [:threedaily, :threeweekly, :threedaymonthly, :threedatemonthly].include?(repeats)
|
67
64
|
end
|
68
65
|
end
|
69
66
|
|
70
67
|
def variant_of?(sym)
|
71
68
|
case sym
|
72
|
-
when :daily then [:daily, :altdaily, :threedaily].include?(
|
73
|
-
when :weekly then [:weekly, :altweekly, :threeweekly].include?(
|
74
|
-
when :daymonthly then [:daymonthly, :altdaymonthly, :threedaymonthly].include?(
|
75
|
-
when :datemonthly then [:datemonthly, :altdatemonthly, :threedatemonthly].include?(
|
69
|
+
when :daily then [:daily, :altdaily, :threedaily].include?(repeats)
|
70
|
+
when :weekly then [:weekly, :altweekly, :threeweekly].include?(repeats)
|
71
|
+
when :daymonthly then [:daymonthly, :altdaymonthly, :threedaymonthly].include?(repeats)
|
72
|
+
when :datemonthly then [:datemonthly, :altdatemonthly, :threedatemonthly].include?(repeats)
|
76
73
|
end
|
77
74
|
end
|
78
75
|
|
@@ -81,37 +78,37 @@ module Nickel
|
|
81
78
|
[hash_for_occ_base]
|
82
79
|
end
|
83
80
|
|
84
|
-
#
|
85
|
-
# "every monday and wed" will produce
|
81
|
+
# repeats_on is an array of day indices. For example,
|
82
|
+
# "every monday and wed" will produce repeats_on == [0,2].
|
86
83
|
def interpret_weekly_variant
|
87
84
|
hash_for_occ_base = {:type => :weekly, :interval => get_interval}
|
88
85
|
array_of_occurrences = []
|
89
|
-
|
86
|
+
repeats_on.each do |day_of_week|
|
90
87
|
array_of_occurrences << hash_for_occ_base.merge({:day_of_week => day_of_week})
|
91
88
|
end
|
92
89
|
array_of_occurrences
|
93
90
|
end
|
94
91
|
|
95
|
-
#
|
96
|
-
# [week_of_month, day_of_week]. For example,
|
92
|
+
# repeats_on is an array of arrays: Each sub array has the format
|
93
|
+
# [week_of_month, day_of_week]. For example,
|
97
94
|
# "the first and second sat of every month" will produce
|
98
|
-
#
|
95
|
+
# repeats_on == [[1,5], [2,5]]
|
99
96
|
def interpret_daymonthly_variant
|
100
97
|
hash_for_occ_base = {:type => :daymonthly, :interval => get_interval}
|
101
98
|
array_of_occurrences = []
|
102
|
-
|
99
|
+
repeats_on.each do |on|
|
103
100
|
h = {:week_of_month => on[0], :day_of_week => on[1]}
|
104
101
|
array_of_occurrences << hash_for_occ_base.merge(h)
|
105
102
|
end
|
106
103
|
array_of_occurrences
|
107
104
|
end
|
108
105
|
|
109
|
-
#
|
110
|
-
# "the 21st and 22nd of every monthy" will produce
|
106
|
+
# repeats_on is an array of datemonthly indices. For example,
|
107
|
+
# "the 21st and 22nd of every monthy" will produce repeats_on == [21, 22]
|
111
108
|
def interpret_datemonthly_variant
|
112
109
|
hash_for_occ_base = {:type => :datemonthly, :interval => get_interval}
|
113
110
|
array_of_occurrences = []
|
114
|
-
|
111
|
+
repeats_on.each do |date_of_month|
|
115
112
|
h = {:date_of_month => date_of_month}
|
116
113
|
array_of_occurrences << hash_for_occ_base.merge(h)
|
117
114
|
end
|
@@ -1,29 +1,27 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
1
|
+
require_relative 'construct'
|
2
|
+
require_relative 'zdate'
|
3
|
+
require_relative 'ztime'
|
4
4
|
|
5
5
|
module Nickel
|
6
6
|
|
7
7
|
class ConstructFinder
|
8
8
|
attr_reader :constructs, :components
|
9
|
-
|
9
|
+
|
10
10
|
def initialize(query, curdate, curtime)
|
11
|
-
# If query is a string (for debug), use it to initialize NLPQuery.
|
12
|
-
query.class == String && query = NLPQuery.new(query)
|
13
11
|
@curdate = curdate
|
14
12
|
@curtime = curtime
|
15
13
|
@components = query.split
|
16
14
|
@pos = 0 # iterator
|
17
15
|
@constructs = []
|
18
16
|
end
|
19
|
-
|
17
|
+
|
20
18
|
def run
|
21
19
|
while @pos < @components.size
|
22
20
|
big_if_on_current_word
|
23
21
|
@pos += 1
|
24
22
|
end
|
25
23
|
end
|
26
|
-
|
24
|
+
|
27
25
|
def reset_instance_vars
|
28
26
|
@day_index = nil
|
29
27
|
@month_index = nil
|
@@ -35,174 +33,174 @@ module Nickel
|
|
35
33
|
@date1 = nil
|
36
34
|
@date2 = nil
|
37
35
|
end
|
38
|
-
|
36
|
+
|
39
37
|
def big_if_on_current_word
|
40
38
|
reset_instance_vars
|
41
|
-
|
39
|
+
|
42
40
|
if match_every
|
43
41
|
if match_every_dayname then found_every_dayname # every tue
|
44
42
|
elsif match_every_day then found_every_day # every day
|
45
|
-
elsif match_every_other
|
43
|
+
elsif match_every_other
|
46
44
|
if match_every_other_dayname then found_every_other_dayname # every other fri
|
47
45
|
elsif match_every_other_day then found_every_other_day # every other day
|
48
|
-
end
|
49
|
-
elsif match_every_3rd
|
46
|
+
end
|
47
|
+
elsif match_every_3rd
|
50
48
|
if match_every_3rd_dayname then found_every_3rd_dayname # every third fri
|
51
49
|
elsif match_every_3rd_day then found_every_3rd_day # every third day
|
52
|
-
end
|
53
|
-
end
|
54
|
-
|
55
|
-
elsif match_repeats
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
elsif match_repeats
|
56
54
|
if match_repeats_daily then found_repeats_daily # repeats daily
|
57
55
|
elsif match_repeats_altdaily then found_repeats_altdaily # repeats altdaily
|
58
56
|
elsif match_repeats_weekly_vague then found_repeats_weekly_vague # repeats weekly
|
59
57
|
elsif match_repeats_altweekly_vague then found_repeats_altweekly_vague # repeats altweekly
|
60
|
-
elsif match_repeats_monthly
|
58
|
+
elsif match_repeats_monthly
|
61
59
|
if match_repeats_daymonthly then found_repeats_daymonthly # repeats monthly 1st fri
|
62
60
|
elsif match_repeats_datemonthly then found_repeats_datemonthly # repeats monthly 22nd
|
63
|
-
end
|
64
|
-
elsif match_repeats_altmonthly
|
61
|
+
end
|
62
|
+
elsif match_repeats_altmonthly
|
65
63
|
if match_repeats_altmonthly_daymonthly then found_repeats_altmonthly_daymonthly # repeats altmonthly 1st fri
|
66
64
|
elsif match_repeats_altmonthly_datemonthly then found_repeats_altmonthly_datemonthly # repeats altmonthly 22nd
|
67
|
-
end
|
68
|
-
elsif match_repeats_threemonthly
|
65
|
+
end
|
66
|
+
elsif match_repeats_threemonthly
|
69
67
|
if match_repeats_threemonthly_daymonthly then found_repeats_threemonthly_daymonthly # repeats threemonthly 1st fri
|
70
68
|
elsif match_repeats_threemonthly_datemonthly then found_repeats_threemonthly_datemonthly # repeats threemonthly 22nd
|
71
|
-
end
|
72
|
-
end
|
73
|
-
|
74
|
-
elsif match_for_x
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
elsif match_for_x
|
75
73
|
if match_for_x_days then found_for_x_days # for 10 days
|
76
74
|
elsif match_for_x_weeks then found_for_x_weeks # for 10 weeks
|
77
75
|
elsif match_for_x_months then found_for_x_months # for 10 months
|
78
|
-
end
|
79
|
-
|
80
|
-
elsif match_this
|
76
|
+
end
|
77
|
+
|
78
|
+
elsif match_this
|
81
79
|
if match_this_dayname then found_this_dayname # this fri
|
82
80
|
elsif match_this_week then found_this_week # this week
|
83
81
|
elsif match_this_month then found_this_month # this month (implies 9/1 to 9/30)
|
84
|
-
end # SHOULDN'T "this" HAVE "this weekend" ???
|
85
|
-
|
86
|
-
elsif match_next
|
82
|
+
end # SHOULDN'T "this" HAVE "this weekend" ???
|
83
|
+
|
84
|
+
elsif match_next
|
87
85
|
if match_next_weekend then found_next_weekend # next weekend --- never hit?
|
88
86
|
elsif match_next_dayname then found_next_dayname # next tuesday
|
89
|
-
elsif match_next_x
|
87
|
+
elsif match_next_x
|
90
88
|
if match_next_x_days then found_next_x_days # next 5 days --- shouldn't this be a wrapper?
|
91
89
|
elsif match_next_x_weeks then found_next_x_weeks # next 5 weeks --- shouldn't this be a wrapper?
|
92
90
|
elsif match_next_x_months then found_next_x_months # next 5 months --- shouldn't this be a wrapper?
|
93
91
|
elsif match_next_x_years then found_next_x_years # next 5 years --- shouldn't this be a wrapper?
|
94
|
-
end
|
92
|
+
end
|
95
93
|
elsif match_next_week then found_next_week
|
96
94
|
elsif match_next_month then found_next_month # next month (implies 10/1 to 10/31)
|
97
|
-
end
|
98
|
-
|
95
|
+
end
|
96
|
+
|
99
97
|
elsif match_week
|
100
98
|
if match_week_of_date then found_week_of_date # week of 1/2
|
101
99
|
elsif match_week_through_date then found_week_through_date # week through 1/2 (as in, week ending 1/2)
|
102
100
|
end
|
103
|
-
|
104
|
-
elsif match_x_weeks_from
|
101
|
+
|
102
|
+
elsif match_x_weeks_from
|
105
103
|
if match_x_weeks_from_dayname then found_x_weeks_from_dayname # 5 weeks from tuesday
|
106
104
|
elsif match_x_weeks_from_this_dayname then found_x_weeks_from_this_dayname # 5 weeks from this tuesday
|
107
105
|
elsif match_x_weeks_from_next_dayname then found_x_weeks_from_next_dayname # 5 weeks from next tuesday
|
108
106
|
elsif match_x_weeks_from_tomorrow then found_x_weeks_from_tomorrow # 5 weeks from tomorrow
|
109
107
|
elsif match_x_weeks_from_now then found_x_weeks_from_now # 5 weeks from now
|
110
108
|
elsif match_x_weeks_from_yesterday then found_x_weeks_from_yesterday # 5 weeks from yesterday
|
111
|
-
end
|
112
|
-
|
113
|
-
elsif match_x_months_from
|
109
|
+
end
|
110
|
+
|
111
|
+
elsif match_x_months_from
|
114
112
|
if match_x_months_from_dayname then found_x_months_from_dayname # 2 months from wed
|
115
113
|
elsif match_x_months_from_this_dayname then found_x_months_from_this_dayname # 2 months from this wed
|
116
114
|
elsif match_x_months_from_next_dayname then found_x_months_from_next_dayname # 2 months from next wed
|
117
115
|
elsif match_x_months_from_tomorrow then found_x_months_from_tomorrow # 2 months from tomorrow
|
118
116
|
elsif match_x_months_from_now then found_x_months_from_now # 2 months from now
|
119
117
|
elsif match_x_months_from_yesterday then found_x_months_from_yesterday # 2 months from yesterday
|
120
|
-
end
|
121
|
-
|
122
|
-
elsif match_x_days_from
|
118
|
+
end
|
119
|
+
|
120
|
+
elsif match_x_days_from
|
123
121
|
if match_x_days_from_now then found_x_days_from_now # 5 days from now
|
124
122
|
elsif match_x_days_from_dayname then found_x_days_from_dayname # 5 days from monday
|
125
|
-
end
|
126
|
-
|
127
|
-
elsif match_x_dayname_from
|
123
|
+
end
|
124
|
+
|
125
|
+
elsif match_x_dayname_from
|
128
126
|
if match_x_dayname_from_now then found_x_dayname_from_now # 2 fridays from now
|
129
127
|
elsif match_x_dayname_from_tomorrow then found_x_dayname_from_tomorrow # 2 fridays from tomorrow
|
130
128
|
elsif match_x_dayname_from_yesterday then found_x_dayname_from_yesterday # 2 fridays from yesterday
|
131
129
|
elsif match_x_dayname_from_this then found_x_dayname_from_this # 2 fridays from this one
|
132
130
|
elsif match_x_dayname_from_next then found_x_dayname_from_next # 2 fridays from next friday
|
133
|
-
end
|
131
|
+
end
|
134
132
|
|
135
133
|
elsif match_x_minutes_from_now then found_x_minutes_from_now # 5 minutes from now
|
136
134
|
elsif match_x_hours_from_now then found_x_hours_from_now # 5 hours from now
|
137
135
|
|
138
|
-
elsif match_ordinal_dayname
|
136
|
+
elsif match_ordinal_dayname
|
139
137
|
if match_ordinal_dayname_this_month then found_ordinal_dayname_this_month # 2nd friday this month
|
140
138
|
elsif match_ordinal_dayname_next_month then found_ordinal_dayname_next_month # 2nd friday next month
|
141
139
|
elsif match_ordinal_dayname_monthname then found_ordinal_dayname_monthname # 2nd friday december
|
142
|
-
end
|
143
|
-
|
140
|
+
end
|
141
|
+
|
144
142
|
elsif match_ordinal_this_month then found_ordinal_this_month # 28th this month
|
145
143
|
elsif match_ordinal_next_month then found_ordinal_next_month # 28th next month
|
146
|
-
|
147
|
-
elsif match_first_day
|
144
|
+
|
145
|
+
elsif match_first_day
|
148
146
|
if match_first_day_this_month then found_first_day_this_month # first day this month
|
149
147
|
elsif match_first_day_next_month then found_first_day_next_month # first day next month
|
150
148
|
elsif match_first_day_monthname then found_first_day_monthname # first day january (well this is stupid, "first day of january" gets preprocessed into "1/1", so what is the point of this?)
|
151
|
-
end
|
152
|
-
|
153
|
-
elsif match_last_day
|
149
|
+
end
|
150
|
+
|
151
|
+
elsif match_last_day
|
154
152
|
if match_last_day_this_month then found_last_day_this_month # last day this month
|
155
153
|
elsif match_last_day_next_month then found_last_day_next_month # last day next month
|
156
154
|
elsif match_last_day_monthname then found_last_day_monthname # last day november
|
157
|
-
end
|
158
|
-
|
159
|
-
elsif match_at
|
160
|
-
if match_at_time
|
155
|
+
end
|
156
|
+
|
157
|
+
elsif match_at
|
158
|
+
if match_at_time
|
161
159
|
if match_at_time_through_time then found_at_time_through_time # at 2 through 5pm
|
162
160
|
else found_at_time # at 2
|
163
|
-
end
|
164
|
-
end
|
165
|
-
|
161
|
+
end
|
162
|
+
end
|
163
|
+
|
166
164
|
elsif match_all_day then found_all_day # all day
|
167
|
-
|
168
|
-
elsif match_tomorrow
|
169
|
-
if match_tomorrow_through
|
165
|
+
|
166
|
+
elsif match_tomorrow
|
167
|
+
if match_tomorrow_through
|
170
168
|
if match_tomorrow_through_dayname then found_tomorrow_through_dayname # tomorrow through friday
|
171
169
|
elsif match_tomorrow_through_date then found_tomorrow_through_date # tomorrow through august 20th
|
172
|
-
end
|
170
|
+
end
|
173
171
|
else found_tomorrow # tomorrow
|
174
|
-
end
|
175
|
-
|
176
|
-
elsif match_now
|
177
|
-
if match_now_through
|
172
|
+
end
|
173
|
+
|
174
|
+
elsif match_now
|
175
|
+
if match_now_through
|
178
176
|
if match_now_through_dayname then found_now_through_dayname # today through friday
|
179
177
|
elsif match_now_through_following_dayname then found_now_through_following_dayname # REDUNDANT, PREPROCESS THIS OUT
|
180
178
|
elsif match_now_through_date then found_now_through_date # today through 10/1
|
181
179
|
elsif match_now_through_tomorrow then found_now_through_tomorrow # today through tomorrow
|
182
180
|
elsif match_now_through_next_dayname then found_now_through_next_dayname # today through next friday
|
183
|
-
end
|
181
|
+
end
|
184
182
|
else found_now # today
|
185
|
-
end
|
186
|
-
|
187
|
-
elsif match_dayname
|
183
|
+
end
|
184
|
+
|
185
|
+
elsif match_dayname
|
188
186
|
if match_dayname_the_ordinal then found_dayname_the_ordinal # monday the 21st
|
189
187
|
elsif match_dayname_x_weeks_from_next then found_dayname_x_weeks_from_next # monday 2 weeks from next
|
190
188
|
elsif match_dayname_x_weeks_from_this then found_dayname_x_weeks_from_this # monday 2 weeks from this
|
191
189
|
else found_dayname # monday (also monday tuesday wed...)
|
192
|
-
end
|
193
|
-
|
190
|
+
end
|
191
|
+
|
194
192
|
elsif match_through_monthname then found_through_monthname # through december (implies through 11/30)
|
195
193
|
elsif match_monthname then found_monthname # december (implies 12/1 to 12/31)
|
196
|
-
|
197
|
-
# 5th constructor
|
194
|
+
|
195
|
+
# 5th constructor
|
198
196
|
elsif match_start then found_start
|
199
197
|
elsif match_through then found_through
|
200
|
-
|
198
|
+
|
201
199
|
elsif match_time # match time second to last
|
202
200
|
if match_time_through_time then found_time_through_time # 10 to 4
|
203
201
|
else found_time # 10
|
204
202
|
end
|
205
|
-
|
203
|
+
|
206
204
|
elsif match_date # match date last
|
207
205
|
if match_date_through_date then found_date_through_date # 5th through the 16th
|
208
206
|
else found_date # 5th
|
@@ -213,11 +211,11 @@ module Nickel
|
|
213
211
|
def match_every
|
214
212
|
@components[@pos]=="every"
|
215
213
|
end
|
216
|
-
|
214
|
+
|
217
215
|
def match_every_dayname
|
218
216
|
@day_index = ZDate.days_of_week.index(@components[@pos+1]) # if "every [day]"
|
219
217
|
end
|
220
|
-
|
218
|
+
|
221
219
|
def found_every_dayname
|
222
220
|
day_array=[@day_index]
|
223
221
|
j = 2
|
@@ -225,25 +223,25 @@ module Nickel
|
|
225
223
|
day_array << ZDate.days_of_week.index(@components[@pos+j])
|
226
224
|
j += 1
|
227
225
|
end
|
228
|
-
@constructs << RecurrenceConstruct.new(:repeats => :weekly, :repeats_on => day_array, :comp_start => @pos, :comp_end => @pos += (j - 1), :found_in =>
|
226
|
+
@constructs << RecurrenceConstruct.new(:repeats => :weekly, :repeats_on => day_array, :comp_start => @pos, :comp_end => @pos += (j - 1), :found_in => __method__)
|
229
227
|
end
|
230
|
-
|
228
|
+
|
231
229
|
def match_every_day
|
232
230
|
@components[@pos+1] == "day"
|
233
231
|
end
|
234
|
-
|
232
|
+
|
235
233
|
def found_every_day
|
236
|
-
@constructs << RecurrenceConstruct.new(:repeats => :daily, :comp_start => @pos, :comp_end => @pos += 1, :found_in =>
|
234
|
+
@constructs << RecurrenceConstruct.new(:repeats => :daily, :comp_start => @pos, :comp_end => @pos += 1, :found_in => __method__)
|
237
235
|
end
|
238
236
|
|
239
237
|
def match_every_other
|
240
238
|
@components[@pos+1] =~ /other|2nd/
|
241
239
|
end
|
242
|
-
|
240
|
+
|
243
241
|
def match_every_other_dayname
|
244
242
|
@day_index = ZDate.days_of_week.index(@components[@pos+2]) # if "every other mon"
|
245
243
|
end
|
246
|
-
|
244
|
+
|
247
245
|
def found_every_other_dayname
|
248
246
|
day_array = [@day_index]
|
249
247
|
j = 3
|
@@ -251,25 +249,25 @@ module Nickel
|
|
251
249
|
day_array << ZDate.days_of_week.index(@components[@pos+j])
|
252
250
|
j += 1
|
253
251
|
end
|
254
|
-
@constructs << RecurrenceConstruct.new(:repeats => :altweekly, :repeats_on => day_array, :comp_start => @pos, :comp_end => @pos += (j - 1), :found_in =>
|
252
|
+
@constructs << RecurrenceConstruct.new(:repeats => :altweekly, :repeats_on => day_array, :comp_start => @pos, :comp_end => @pos += (j - 1), :found_in => __method__)
|
255
253
|
end
|
256
|
-
|
254
|
+
|
257
255
|
def match_every_other_day
|
258
256
|
@components[@pos+2] == "day" ## if "every other day"
|
259
257
|
end
|
260
|
-
|
258
|
+
|
261
259
|
def found_every_other_day
|
262
|
-
@constructs << RecurrenceConstruct.new(:repeats => :altdaily, :comp_start => @pos, :comp_end => @pos += 2, :found_in =>
|
260
|
+
@constructs << RecurrenceConstruct.new(:repeats => :altdaily, :comp_start => @pos, :comp_end => @pos += 2, :found_in => __method__)
|
263
261
|
end
|
264
262
|
|
265
263
|
def match_every_3rd
|
266
264
|
@components[@pos+1] == "3rd"
|
267
265
|
end
|
268
|
-
|
266
|
+
|
269
267
|
def match_every_3rd_dayname
|
270
268
|
@day_index = ZDate.days_of_week.index(@components[@pos+2]) # if "every 3rd tue"
|
271
269
|
end
|
272
|
-
|
270
|
+
|
273
271
|
def found_every_3rd_dayname
|
274
272
|
day_array = [@day_index]
|
275
273
|
j = 3
|
@@ -277,27 +275,27 @@ module Nickel
|
|
277
275
|
day_array << ZDate.days_of_week.index(@components[@pos+j])
|
278
276
|
j += 1
|
279
277
|
end
|
280
|
-
@constructs << RecurrenceConstruct.new(:repeats => :threeweekly, :repeats_on => day_array, :comp_start => @pos, :comp_end => @pos += (j - 1), :found_in =>
|
278
|
+
@constructs << RecurrenceConstruct.new(:repeats => :threeweekly, :repeats_on => day_array, :comp_start => @pos, :comp_end => @pos += (j - 1), :found_in => __method__)
|
281
279
|
end
|
282
|
-
|
280
|
+
|
283
281
|
def match_every_3rd_day
|
284
282
|
@components[@pos+2] == "day" ## if "every 3rd day"
|
285
283
|
end
|
286
|
-
|
284
|
+
|
287
285
|
def found_every_3rd_day
|
288
|
-
@constructs << RecurrenceConstruct.new(:repeats => :threedaily, :comp_start => @pos, :comp_end => @pos += 2, :found_in =>
|
286
|
+
@constructs << RecurrenceConstruct.new(:repeats => :threedaily, :comp_start => @pos, :comp_end => @pos += 2, :found_in => __method__)
|
289
287
|
end
|
290
288
|
|
291
289
|
def match_repeats
|
292
290
|
@components[@pos] == "repeats"
|
293
291
|
end
|
294
|
-
|
292
|
+
|
295
293
|
def match_repeats_daily
|
296
|
-
@components[@pos+1] == "daily"
|
294
|
+
@components[@pos+1] == "daily"
|
297
295
|
end
|
298
296
|
|
299
297
|
def found_repeats_daily
|
300
|
-
@constructs << RecurrenceConstruct.new(:repeats => :daily, :comp_start => @pos, :comp_end => @pos += 1, :found_in =>
|
298
|
+
@constructs << RecurrenceConstruct.new(:repeats => :daily, :comp_start => @pos, :comp_end => @pos += 1, :found_in => __method__)
|
301
299
|
end
|
302
300
|
|
303
301
|
def match_repeats_altdaily
|
@@ -305,7 +303,7 @@ module Nickel
|
|
305
303
|
end
|
306
304
|
|
307
305
|
def found_repeats_altdaily
|
308
|
-
@constructs << RecurrenceConstruct.new(:repeats => :altdaily, :comp_start => @pos, :comp_end => @pos += 1, :found_in =>
|
306
|
+
@constructs << RecurrenceConstruct.new(:repeats => :altdaily, :comp_start => @pos, :comp_end => @pos += 1, :found_in => __method__)
|
309
307
|
end
|
310
308
|
|
311
309
|
def match_repeats_weekly_vague
|
@@ -313,7 +311,7 @@ module Nickel
|
|
313
311
|
end
|
314
312
|
|
315
313
|
def found_repeats_weekly_vague
|
316
|
-
@constructs << RecurrenceConstruct.new(:repeats => :weekly, :comp_start => @pos, :comp_end => @pos += 1, :found_in =>
|
314
|
+
@constructs << RecurrenceConstruct.new(:repeats => :weekly, :comp_start => @pos, :comp_end => @pos += 1, :found_in => __method__)
|
317
315
|
end
|
318
316
|
|
319
317
|
def match_repeats_altweekly_vague
|
@@ -321,7 +319,7 @@ module Nickel
|
|
321
319
|
end
|
322
320
|
|
323
321
|
def found_repeats_altweekly_vague
|
324
|
-
@constructs << RecurrenceConstruct.new(:repeats => :altweekly, :comp_start => @pos, :comp_end => @pos += 1, :found_in =>
|
322
|
+
@constructs << RecurrenceConstruct.new(:repeats => :altweekly, :comp_start => @pos, :comp_end => @pos += 1, :found_in => __method__)
|
325
323
|
end
|
326
324
|
|
327
325
|
def match_repeats_monthly
|
@@ -339,22 +337,22 @@ module Nickel
|
|
339
337
|
rep_array << [@week_num, @day_index]
|
340
338
|
j += 2
|
341
339
|
end
|
342
|
-
@constructs << RecurrenceConstruct.new(:repeats => :daymonthly, :repeats_on => rep_array, :comp_start => @pos, :comp_end => @pos += (j - 1), :found_in =>
|
340
|
+
@constructs << RecurrenceConstruct.new(:repeats => :daymonthly, :repeats_on => rep_array, :comp_start => @pos, :comp_end => @pos += (j - 1), :found_in => __method__)
|
343
341
|
end
|
344
342
|
|
345
343
|
def match_repeats_datemonthly
|
346
|
-
@components[@pos+2] && @components[@pos+2]
|
344
|
+
@components[@pos+2] && ConstructFinder.ordinal_only?(@components[@pos+2]) && @date_array = [@components[@pos+2].to_i] # repeats monthly 22nd
|
347
345
|
end
|
348
346
|
|
349
347
|
def found_repeats_datemonthly
|
350
348
|
j = 3
|
351
|
-
while @components[@pos+j] && @components[@pos+j]
|
349
|
+
while @components[@pos+j] && ConstructFinder.ordinal_only?(@components[@pos+j])
|
352
350
|
@date_array << @components[@pos+j].to_i
|
353
351
|
j += 1
|
354
352
|
end
|
355
|
-
@constructs << RecurrenceConstruct.new(:repeats => :datemonthly, :repeats_on => @date_array, :comp_start => @pos, :comp_end => @pos += (j - 1), :found_in =>
|
353
|
+
@constructs << RecurrenceConstruct.new(:repeats => :datemonthly, :repeats_on => @date_array, :comp_start => @pos, :comp_end => @pos += (j - 1), :found_in => __method__)
|
356
354
|
end
|
357
|
-
|
355
|
+
|
358
356
|
def match_repeats_altmonthly
|
359
357
|
@components[@pos+1] == "altmonthly"
|
360
358
|
end
|
@@ -370,22 +368,22 @@ module Nickel
|
|
370
368
|
rep_array << [@week_num, @day_index]
|
371
369
|
j += 2
|
372
370
|
end
|
373
|
-
@constructs << RecurrenceConstruct.new(:repeats => :altdaymonthly, :repeats_on => rep_array, :comp_start => @pos, :comp_end => @pos += (j - 1), :found_in =>
|
371
|
+
@constructs << RecurrenceConstruct.new(:repeats => :altdaymonthly, :repeats_on => rep_array, :comp_start => @pos, :comp_end => @pos += (j - 1), :found_in => __method__)
|
374
372
|
end
|
375
373
|
|
376
374
|
def match_repeats_altmonthly_datemonthly
|
377
|
-
@components[@pos+2] && @components[@pos+2]
|
375
|
+
@components[@pos+2] && ConstructFinder.ordinal_only?(@components[@pos+2]) && @date_array = [@components[@pos+2].to_i] # repeats altmonthly 22nd
|
378
376
|
end
|
379
377
|
|
380
378
|
def found_repeats_altmonthly_datemonthly
|
381
379
|
j = 3
|
382
|
-
while @components[@pos+j] && @components[@pos+j]
|
380
|
+
while @components[@pos+j] && ConstructFinder.ordinal_only?(@components[@pos+j])
|
383
381
|
@date_array << @components[@pos+j].to_i
|
384
382
|
j += 1
|
385
383
|
end
|
386
|
-
@constructs << RecurrenceConstruct.new(:repeats => :altdatemonthly, :repeats_on => @date_array, :comp_start => @pos, :comp_end => @pos += (j - 1), :found_in =>
|
384
|
+
@constructs << RecurrenceConstruct.new(:repeats => :altdatemonthly, :repeats_on => @date_array, :comp_start => @pos, :comp_end => @pos += (j - 1), :found_in => __method__)
|
387
385
|
end
|
388
|
-
|
386
|
+
|
389
387
|
def match_repeats_threemonthly
|
390
388
|
@components[@pos+1] == "threemonthly"
|
391
389
|
end
|
@@ -401,32 +399,32 @@ module Nickel
|
|
401
399
|
rep_array << [@week_num, @day_index]
|
402
400
|
j += 2
|
403
401
|
end
|
404
|
-
@constructs << RecurrenceConstruct.new(:repeats => :threedaymonthly, :repeats_on => rep_array, :comp_start => @pos, :comp_end => @pos += (j - 1), :found_in =>
|
402
|
+
@constructs << RecurrenceConstruct.new(:repeats => :threedaymonthly, :repeats_on => rep_array, :comp_start => @pos, :comp_end => @pos += (j - 1), :found_in => __method__)
|
405
403
|
end
|
406
404
|
|
407
405
|
def match_repeats_threemonthly_datemonthly
|
408
|
-
@components[@pos+2] && @components[@pos+2]
|
409
|
-
end
|
406
|
+
@components[@pos+2] && ConstructFinder.ordinal_only?(@components[@pos+2]) && @date_array = [@components[@pos+2].to_i] # repeats threemonthly 22nd
|
407
|
+
end
|
410
408
|
|
411
409
|
def found_repeats_threemonthly_datemonthly
|
412
410
|
j = 3
|
413
|
-
while @components[@pos+j] && @components[@pos+j]
|
411
|
+
while @components[@pos+j] && ConstructFinder.ordinal_only?(@components[@pos+j])
|
414
412
|
@date_array << @components[@pos+j].to_i
|
415
413
|
j += 1
|
416
414
|
end
|
417
|
-
@constructs << RecurrenceConstruct.new(:repeats => :threedatemonthly, :repeats_on => @date_array, :comp_start => @pos, :comp_end => @pos += (j - 1), :found_in =>
|
415
|
+
@constructs << RecurrenceConstruct.new(:repeats => :threedatemonthly, :repeats_on => @date_array, :comp_start => @pos, :comp_end => @pos += (j - 1), :found_in => __method__)
|
418
416
|
end
|
419
417
|
|
420
418
|
def match_for_x
|
421
|
-
@components[@pos]=="for" && @components[@pos+1]
|
422
|
-
end
|
419
|
+
@components[@pos]=="for" && ConstructFinder.digits_only?(@components[@pos+1]) && @length = @components[@pos+1].to_i
|
420
|
+
end
|
423
421
|
|
424
422
|
def match_for_x_days
|
425
423
|
@components[@pos+2] =~ /days?/
|
426
424
|
end
|
427
425
|
|
428
426
|
def found_for_x_days
|
429
|
-
@constructs << WrapperConstruct.new(:wrapper_type => 2, :wrapper_length => @length, :comp_start => @pos, :comp_end => @pos += 2, :found_in =>
|
427
|
+
@constructs << WrapperConstruct.new(:wrapper_type => 2, :wrapper_length => @length, :comp_start => @pos, :comp_end => @pos += 2, :found_in => __method__)
|
430
428
|
end
|
431
429
|
|
432
430
|
def match_for_x_weeks
|
@@ -434,7 +432,7 @@ module Nickel
|
|
434
432
|
end
|
435
433
|
|
436
434
|
def found_for_x_weeks
|
437
|
-
@constructs << WrapperConstruct.new(:wrapper_type => 3, :wrapper_length => @length, :comp_start => @pos, :comp_end => @pos += 2, :found_in =>
|
435
|
+
@constructs << WrapperConstruct.new(:wrapper_type => 3, :wrapper_length => @length, :comp_start => @pos, :comp_end => @pos += 2, :found_in => __method__)
|
438
436
|
end
|
439
437
|
|
440
438
|
def match_for_x_months
|
@@ -442,9 +440,9 @@ module Nickel
|
|
442
440
|
end
|
443
441
|
|
444
442
|
def found_for_x_months
|
445
|
-
@constructs << WrapperConstruct.new(:wrapper_type => 4, :wrapper_length => @length, :comp_start => @pos, :comp_end => @pos += 2, :found_in =>
|
443
|
+
@constructs << WrapperConstruct.new(:wrapper_type => 4, :wrapper_length => @length, :comp_start => @pos, :comp_end => @pos += 2, :found_in => __method__)
|
446
444
|
end
|
447
|
-
|
445
|
+
|
448
446
|
def match_this
|
449
447
|
@components[@pos]=="this"
|
450
448
|
end
|
@@ -455,10 +453,10 @@ module Nickel
|
|
455
453
|
|
456
454
|
def found_this_dayname
|
457
455
|
day_to_add = @curdate.this(@day_index)
|
458
|
-
@constructs << DateConstruct.new(:date => day_to_add, :comp_start => @pos, :comp_end => @pos += 1, :found_in =>
|
456
|
+
@constructs << DateConstruct.new(:date => day_to_add, :comp_start => @pos, :comp_end => @pos += 1, :found_in => __method__)
|
459
457
|
while @components[@pos+1] && @day_index = ZDate.days_of_week.index(@components[@pos+1])
|
460
458
|
# note @pos gets incremented on each pass
|
461
|
-
@constructs << DateConstruct.new(:date => day_to_add = day_to_add.this(@day_index), :comp_start => @pos + 1, :comp_end => @pos += 1, :found_in =>
|
459
|
+
@constructs << DateConstruct.new(:date => day_to_add = day_to_add.this(@day_index), :comp_start => @pos + 1, :comp_end => @pos += 1, :found_in => __method__)
|
462
460
|
end
|
463
461
|
end
|
464
462
|
|
@@ -467,7 +465,7 @@ module Nickel
|
|
467
465
|
end
|
468
466
|
|
469
467
|
def found_this_week
|
470
|
-
@constructs << DateSpanConstruct.new(:start_date => @curdate, :end_date => @curdate.add_days(7), :comp_start => @pos, :comp_end => @pos += 1, :found_in =>
|
468
|
+
@constructs << DateSpanConstruct.new(:start_date => @curdate, :end_date => @curdate.add_days(7), :comp_start => @pos, :comp_end => @pos += 1, :found_in => __method__)
|
471
469
|
end
|
472
470
|
|
473
471
|
def match_this_month
|
@@ -475,10 +473,9 @@ module Nickel
|
|
475
473
|
end
|
476
474
|
|
477
475
|
def found_this_month
|
478
|
-
|
479
|
-
@constructs << DateSpanConstruct.new(:start_date => date, :end_date => @curdate.end_of_month, :comp_start => @pos, :comp_end => @pos += 1, :found_in => method_name)
|
476
|
+
@constructs << DateSpanConstruct.new(:start_date => @curdate, :end_date => @curdate.end_of_month, :comp_start => @pos, :comp_end => @pos += 1, :found_in => __method__)
|
480
477
|
end
|
481
|
-
|
478
|
+
|
482
479
|
|
483
480
|
def match_next
|
484
481
|
@components[@pos]=="next"
|
@@ -489,7 +486,7 @@ module Nickel
|
|
489
486
|
end
|
490
487
|
|
491
488
|
def found_next_weekend
|
492
|
-
dsc = DateSpanConstruct.new(:start_date => @curdate.next(5), :comp_start => @pos, :comp_end => @pos += 1, :found_in =>
|
489
|
+
dsc = DateSpanConstruct.new(:start_date => @curdate.next(5), :comp_start => @pos, :comp_end => @pos += 1, :found_in => __method__)
|
493
490
|
dsc.end_date = dsc.start_date.add_days(1)
|
494
491
|
@constructs << dsc
|
495
492
|
end
|
@@ -500,15 +497,15 @@ module Nickel
|
|
500
497
|
|
501
498
|
def found_next_dayname
|
502
499
|
day_to_add = @curdate.next(@day_index)
|
503
|
-
@constructs << DateConstruct.new(:date => day_to_add, :comp_start => @pos, :comp_end => @pos += 1, :found_in =>
|
500
|
+
@constructs << DateConstruct.new(:date => day_to_add, :comp_start => @pos, :comp_end => @pos += 1, :found_in => __method__)
|
504
501
|
while @components[@pos+1] && @day_index = ZDate.days_of_week.index(@components[@pos+1])
|
505
502
|
# note @pos gets incremented on each pass
|
506
|
-
@constructs << DateConstruct.new(:date => day_to_add = day_to_add.this(@day_index), :comp_start => @pos + 1, :comp_end => @pos += 1, :found_in =>
|
503
|
+
@constructs << DateConstruct.new(:date => day_to_add = day_to_add.this(@day_index), :comp_start => @pos + 1, :comp_end => @pos += 1, :found_in => __method__)
|
507
504
|
end
|
508
505
|
end
|
509
506
|
|
510
507
|
def match_next_x
|
511
|
-
@components[@pos+1] && @components[@pos+1]
|
508
|
+
@components[@pos+1] && ConstructFinder.digits_only?(@components[@pos+1]) && @length = @components[@pos+1].to_i
|
512
509
|
end
|
513
510
|
|
514
511
|
def match_next_x_days
|
@@ -516,7 +513,7 @@ module Nickel
|
|
516
513
|
end
|
517
514
|
|
518
515
|
def found_next_x_days
|
519
|
-
@constructs << DateSpanConstruct.new(:start_date => @curdate, :end_date => @curdate.add_days(@length), :comp_start => @pos, :comp_end => @pos += 2, :found_in =>
|
516
|
+
@constructs << DateSpanConstruct.new(:start_date => @curdate, :end_date => @curdate.add_days(@length), :comp_start => @pos, :comp_end => @pos += 2, :found_in => __method__)
|
520
517
|
end
|
521
518
|
|
522
519
|
def match_next_x_weeks
|
@@ -524,7 +521,7 @@ module Nickel
|
|
524
521
|
end
|
525
522
|
|
526
523
|
def found_next_x_weeks
|
527
|
-
@constructs << DateSpanConstruct.new(:start_date => @curdate, :end_date => @curdate.add_weeks(@length), :comp_start => @pos, :comp_end => @pos += 2, :found_in =>
|
524
|
+
@constructs << DateSpanConstruct.new(:start_date => @curdate, :end_date => @curdate.add_weeks(@length), :comp_start => @pos, :comp_end => @pos += 2, :found_in => __method__)
|
528
525
|
end
|
529
526
|
|
530
527
|
def match_next_x_months
|
@@ -532,7 +529,7 @@ module Nickel
|
|
532
529
|
end
|
533
530
|
|
534
531
|
def found_next_x_months
|
535
|
-
@constructs << DateSpanConstruct.new(:start_date => @curdate, :end_date => @curdate.add_months(@length), :comp_start => @pos, :comp_end => @pos += 2, :found_in =>
|
532
|
+
@constructs << DateSpanConstruct.new(:start_date => @curdate, :end_date => @curdate.add_months(@length), :comp_start => @pos, :comp_end => @pos += 2, :found_in => __method__)
|
536
533
|
end
|
537
534
|
|
538
535
|
def match_next_x_years
|
@@ -540,7 +537,7 @@ module Nickel
|
|
540
537
|
end
|
541
538
|
|
542
539
|
def found_next_x_years
|
543
|
-
@constructs << DateSpanConstruct.new(:start_date => @curdate, :end_date => @curdate.add_years(@length), :comp_start => @pos, :comp_end => @pos += 2, :found_in =>
|
540
|
+
@constructs << DateSpanConstruct.new(:start_date => @curdate, :end_date => @curdate.add_years(@length), :comp_start => @pos, :comp_end => @pos += 2, :found_in => __method__)
|
544
541
|
end
|
545
542
|
|
546
543
|
def match_next_week
|
@@ -550,7 +547,7 @@ module Nickel
|
|
550
547
|
def found_next_week
|
551
548
|
sd = @curdate.add_days(7)
|
552
549
|
ed = sd.add_days(7)
|
553
|
-
@constructs << DateSpanConstruct.new(:start_date => sd, :end_date => ed, :comp_start => @pos, :comp_end => @pos += 1, :found_in =>
|
550
|
+
@constructs << DateSpanConstruct.new(:start_date => sd, :end_date => ed, :comp_start => @pos, :comp_end => @pos += 1, :found_in => __method__)
|
554
551
|
end
|
555
552
|
|
556
553
|
def match_next_month
|
@@ -561,31 +558,31 @@ module Nickel
|
|
561
558
|
def found_next_month
|
562
559
|
sd = @curdate.add_months(1).beginning_of_month
|
563
560
|
ed = sd.end_of_month
|
564
|
-
@constructs << DateSpanConstruct.new(:start_date => sd, :end_date => ed, :comp_start => @pos, :comp_end => @pos += 1, :found_in =>
|
561
|
+
@constructs << DateSpanConstruct.new(:start_date => sd, :end_date => ed, :comp_start => @pos, :comp_end => @pos += 1, :found_in => __method__)
|
565
562
|
end
|
566
|
-
|
563
|
+
|
567
564
|
def match_week
|
568
565
|
@components[@pos] == "week"
|
569
566
|
end
|
570
|
-
|
567
|
+
|
571
568
|
def match_week_of_date
|
572
|
-
@components[@pos+1] == "of" && @date1 = @components[@pos+2]
|
569
|
+
@components[@pos+1] == "of" && @date1 = ZDate.interpret(@components[@pos+2], @curdate)
|
573
570
|
end
|
574
571
|
|
575
572
|
def found_week_of_date
|
576
|
-
@constructs << DateSpanConstruct.new(:start_date => @date1, :end_date => @date1.add_days(7), :comp_start => @pos, :comp_end => @pos += 2, :found_in =>
|
573
|
+
@constructs << DateSpanConstruct.new(:start_date => @date1, :end_date => @date1.add_days(7), :comp_start => @pos, :comp_end => @pos += 2, :found_in => __method__)
|
577
574
|
end
|
578
|
-
|
575
|
+
|
579
576
|
def match_week_through_date
|
580
|
-
@components[@pos+1] == "through" && @date1 = @components[@pos+2]
|
577
|
+
@components[@pos+1] == "through" && @date1 = ZDate.interpret(@components[@pos+2], @curdate)
|
581
578
|
end
|
582
579
|
|
583
580
|
def found_week_through_date
|
584
|
-
@constructs << DateSpanConstruct.new(:start_date => @date1.sub_days(7), :end_date => @date1, :comp_start => @pos, :comp_end => @pos += 2, :found_in =>
|
581
|
+
@constructs << DateSpanConstruct.new(:start_date => @date1.sub_days(7), :end_date => @date1, :comp_start => @pos, :comp_end => @pos += 2, :found_in => __method__)
|
585
582
|
end
|
586
|
-
|
583
|
+
|
587
584
|
def match_x_weeks_from
|
588
|
-
@components[@pos]
|
585
|
+
ConstructFinder.digits_only?(@components[@pos]) && @components[@pos+1] =~ /^weeks?$/ && @components[@pos+2] == "from" && @length = @components[@pos].to_i # if "x weeks from"
|
589
586
|
end
|
590
587
|
|
591
588
|
def match_x_weeks_from_dayname
|
@@ -593,18 +590,18 @@ module Nickel
|
|
593
590
|
end
|
594
591
|
|
595
592
|
def found_x_weeks_from_dayname
|
596
|
-
@constructs << DateConstruct.new(:date => @curdate.x_weeks_from_day(@length, @day_index), :comp_start => @pos, :comp_end => @pos += 3, :found_in =>
|
593
|
+
@constructs << DateConstruct.new(:date => @curdate.x_weeks_from_day(@length, @day_index), :comp_start => @pos, :comp_end => @pos += 3, :found_in => __method__)
|
597
594
|
end
|
598
595
|
|
599
596
|
# Reduntant, preprocess out!
|
600
597
|
def match_x_weeks_from_this_dayname
|
601
598
|
@components[@pos+3] == "this" && @day_index = ZDate.days_of_week.index(@components[@pos+4]) # if "x weeks from this monday"
|
602
599
|
end
|
603
|
-
|
600
|
+
|
604
601
|
# Reduntant, preprocess out!
|
605
602
|
def found_x_weeks_from_this_dayname
|
606
603
|
# this is the exact some construct as found_x_weeks_from_dayname, just position and comp_end has to increment by 1 more; pretty stupid, this should be caught in preprocessing
|
607
|
-
@constructs << DateConstruct.new(:date => @curdate.x_weeks_from_day(@length, @day_index), :comp_start => @pos, :comp_end => @pos += 4, :found_in =>
|
604
|
+
@constructs << DateConstruct.new(:date => @curdate.x_weeks_from_day(@length, @day_index), :comp_start => @pos, :comp_end => @pos += 4, :found_in => __method__)
|
608
605
|
end
|
609
606
|
|
610
607
|
def match_x_weeks_from_next_dayname
|
@@ -612,7 +609,7 @@ module Nickel
|
|
612
609
|
end
|
613
610
|
|
614
611
|
def found_x_weeks_from_next_dayname
|
615
|
-
@constructs << DateConstruct.new(:date => @curdate.x_weeks_from_day(@length + 1, @day_index), :comp_start => @pos, :comp_end => @pos += 4, :found_in =>
|
612
|
+
@constructs << DateConstruct.new(:date => @curdate.x_weeks_from_day(@length + 1, @day_index), :comp_start => @pos, :comp_end => @pos += 4, :found_in => __method__)
|
616
613
|
end
|
617
614
|
|
618
615
|
def match_x_weeks_from_tomorrow
|
@@ -620,7 +617,7 @@ module Nickel
|
|
620
617
|
end
|
621
618
|
|
622
619
|
def found_x_weeks_from_tomorrow
|
623
|
-
@constructs << DateConstruct.new(:date => @curdate.add_days(1).add_weeks(@length), :comp_start => @pos, :comp_end => @pos += 3, :found_in =>
|
620
|
+
@constructs << DateConstruct.new(:date => @curdate.add_days(1).add_weeks(@length), :comp_start => @pos, :comp_end => @pos += 3, :found_in => __method__)
|
624
621
|
end
|
625
622
|
|
626
623
|
def match_x_weeks_from_now
|
@@ -628,7 +625,7 @@ module Nickel
|
|
628
625
|
end
|
629
626
|
|
630
627
|
def found_x_weeks_from_now
|
631
|
-
@constructs << DateConstruct.new(:date => @curdate.x_weeks_from_day(@length, @curdate.dayindex), :comp_start => @pos, :comp_end => @pos += 3, :found_in =>
|
628
|
+
@constructs << DateConstruct.new(:date => @curdate.x_weeks_from_day(@length, @curdate.dayindex), :comp_start => @pos, :comp_end => @pos += 3, :found_in => __method__)
|
632
629
|
end
|
633
630
|
|
634
631
|
def match_x_weeks_from_yesterday
|
@@ -636,11 +633,11 @@ module Nickel
|
|
636
633
|
end
|
637
634
|
|
638
635
|
def found_x_weeks_from_yesterday
|
639
|
-
@constructs << DateConstruct.new(:date => @curdate.sub_days(1).add_weeks(@length), :comp_start => @pos, :comp_end => @pos += 3, :found_in =>
|
636
|
+
@constructs << DateConstruct.new(:date => @curdate.sub_days(1).add_weeks(@length), :comp_start => @pos, :comp_end => @pos += 3, :found_in => __method__)
|
640
637
|
end
|
641
|
-
|
638
|
+
|
642
639
|
def match_x_months_from
|
643
|
-
@components[@pos]
|
640
|
+
ConstructFinder.digits_only?(@components[@pos]) && @components[@pos+1] =~ /^months?$/ && @components[@pos+2] == "from" && @length = @components[@pos].to_i # if "x months from"
|
644
641
|
end
|
645
642
|
|
646
643
|
def match_x_months_from_dayname
|
@@ -648,7 +645,7 @@ module Nickel
|
|
648
645
|
end
|
649
646
|
|
650
647
|
def found_x_months_from_dayname
|
651
|
-
@constructs << DateConstruct.new(:date => @curdate.this(@day_index).add_months(@length), :comp_start => @pos, :comp_end => @pos += 3, :found_in =>
|
648
|
+
@constructs << DateConstruct.new(:date => @curdate.this(@day_index).add_months(@length), :comp_start => @pos, :comp_end => @pos += 3, :found_in => __method__)
|
652
649
|
end
|
653
650
|
|
654
651
|
def match_x_months_from_this_dayname
|
@@ -656,7 +653,7 @@ module Nickel
|
|
656
653
|
end
|
657
654
|
|
658
655
|
def found_x_months_from_this_dayname
|
659
|
-
@constructs << DateConstruct.new(:date => @curdate.this(@day_index).add_months(@length), :comp_start => @pos, :comp_end => @pos += 4, :found_in =>
|
656
|
+
@constructs << DateConstruct.new(:date => @curdate.this(@day_index).add_months(@length), :comp_start => @pos, :comp_end => @pos += 4, :found_in => __method__)
|
660
657
|
end
|
661
658
|
|
662
659
|
def match_x_months_from_next_dayname
|
@@ -664,7 +661,7 @@ module Nickel
|
|
664
661
|
end
|
665
662
|
|
666
663
|
def found_x_months_from_next_dayname
|
667
|
-
@constructs << DateConstruct.new(:date => @curdate.next(@day_index).add_months(@length), :comp_start => @pos, :comp_end => @pos += 4, :found_in =>
|
664
|
+
@constructs << DateConstruct.new(:date => @curdate.next(@day_index).add_months(@length), :comp_start => @pos, :comp_end => @pos += 4, :found_in => __method__)
|
668
665
|
end
|
669
666
|
|
670
667
|
def match_x_months_from_tomorrow
|
@@ -672,7 +669,7 @@ module Nickel
|
|
672
669
|
end
|
673
670
|
|
674
671
|
def found_x_months_from_tomorrow
|
675
|
-
@constructs << DateConstruct.new(:date => @curdate.add_days(1).add_months(@length), :comp_start => @pos, :comp_end => @pos += 3, :found_in =>
|
672
|
+
@constructs << DateConstruct.new(:date => @curdate.add_days(1).add_months(@length), :comp_start => @pos, :comp_end => @pos += 3, :found_in => __method__)
|
676
673
|
end
|
677
674
|
|
678
675
|
def match_x_months_from_now
|
@@ -680,7 +677,7 @@ module Nickel
|
|
680
677
|
end
|
681
678
|
|
682
679
|
def found_x_months_from_now
|
683
|
-
@constructs << DateConstruct.new(:date => @curdate.add_months(@length), :comp_start => @pos, :comp_end => @pos += 3, :found_in =>
|
680
|
+
@constructs << DateConstruct.new(:date => @curdate.add_months(@length), :comp_start => @pos, :comp_end => @pos += 3, :found_in => __method__)
|
684
681
|
end
|
685
682
|
|
686
683
|
def match_x_months_from_yesterday
|
@@ -688,11 +685,11 @@ module Nickel
|
|
688
685
|
end
|
689
686
|
|
690
687
|
def found_x_months_from_yesterday
|
691
|
-
@constructs << DateConstruct.new(:date => @curdate.sub_days(1).add_months(@length), :comp_start => @pos, :comp_end => @pos += 3, :found_in =>
|
688
|
+
@constructs << DateConstruct.new(:date => @curdate.sub_days(1).add_months(@length), :comp_start => @pos, :comp_end => @pos += 3, :found_in => __method__)
|
692
689
|
end
|
693
|
-
|
690
|
+
|
694
691
|
def match_x_days_from
|
695
|
-
@components[@pos]
|
692
|
+
ConstructFinder.digits_only?(@components[@pos]) && @components[@pos+1] =~ /^days?$/ && @components[@pos+2] == "from" && @length = @components[@pos].to_i # 3 days from
|
696
693
|
end
|
697
694
|
|
698
695
|
def match_x_days_from_now
|
@@ -700,7 +697,7 @@ module Nickel
|
|
700
697
|
end
|
701
698
|
|
702
699
|
def found_x_days_from_now
|
703
|
-
@constructs << DateConstruct.new(:date => @curdate.add_days(@length), :comp_start => @pos, :comp_end => @pos += 3, :found_in =>
|
700
|
+
@constructs << DateConstruct.new(:date => @curdate.add_days(@length), :comp_start => @pos, :comp_end => @pos += 3, :found_in => __method__)
|
704
701
|
end
|
705
702
|
|
706
703
|
def match_x_days_from_dayname
|
@@ -708,11 +705,11 @@ module Nickel
|
|
708
705
|
end
|
709
706
|
|
710
707
|
def found_x_days_from_dayname
|
711
|
-
@constructs << DateConstruct.new(:date => @curdate.this(@day_index).add_days(@length), :comp_start => @pos, :comp_end => @pos += 3, :found_in =>
|
708
|
+
@constructs << DateConstruct.new(:date => @curdate.this(@day_index).add_days(@length), :comp_start => @pos, :comp_end => @pos += 3, :found_in => __method__)
|
712
709
|
end
|
713
|
-
|
710
|
+
|
714
711
|
def match_x_dayname_from
|
715
|
-
@components[@pos]
|
712
|
+
ConstructFinder.digits_only?(@components[@pos]) && (@day_index = ZDate.days_of_week.index(@components[@pos+1])) && @components[@pos+2] == "from" && @length = @components[@pos].to_i # "2 tuesdays from"
|
716
713
|
end
|
717
714
|
|
718
715
|
def match_x_dayname_from_now
|
@@ -722,7 +719,7 @@ module Nickel
|
|
722
719
|
def found_x_dayname_from_now
|
723
720
|
# this isn't exactly intuitive. If someone says "two tuesday from now" and it is tuesday, they mean "in two weeks." If it is not tuesday, they mean "next tuesday"
|
724
721
|
d = (@days_index == @curdate.dayindex) ? @curdate.add_weeks(@length) : @curdate.x_weeks_from_day(@length - 1, @day_index)
|
725
|
-
@constructs << DateConstruct.new(:date => d, :comp_start => @pos, :comp_end => @pos += 3, :found_in =>
|
722
|
+
@constructs << DateConstruct.new(:date => d, :comp_start => @pos, :comp_end => @pos += 3, :found_in => __method__)
|
726
723
|
end
|
727
724
|
|
728
725
|
def match_x_dayname_from_tomorrow
|
@@ -733,7 +730,7 @@ module Nickel
|
|
733
730
|
# If someone says "two tuesday from tomorrow" and tomorrow is tuesday, they mean "two weeks from tomorrow." If it is not tuesday, this person does not make sense, but we can interpet it as "next tuesday"
|
734
731
|
tomorrow_index = (@curdate.dayindex + 1) % 7
|
735
732
|
d = (@days_index == tomorrow_index) ? @curdate.add_days(1).add_weeks(@length) : @curdate.x_weeks_from_day(@length - 1, @day_index)
|
736
|
-
@constructs << DateConstruct.new(:date => d, :comp_start => @pos, :comp_end => @pos += 3, :found_in =>
|
733
|
+
@constructs << DateConstruct.new(:date => d, :comp_start => @pos, :comp_end => @pos += 3, :found_in => __method__)
|
737
734
|
end
|
738
735
|
|
739
736
|
def match_x_dayname_from_yesterday
|
@@ -744,7 +741,7 @@ module Nickel
|
|
744
741
|
# If someone says "two tuesday from yesterday" and yesterday was tuesday, they mean "two weeks from yesterday." If it is not tuesday, this person does not make sense, but we can interpet it as "next tuesday"
|
745
742
|
yesterday_index = (@curdate.dayindex == 0 ? 6 : @curdate.dayindex - 1)
|
746
743
|
d = (@days_index == yesterday_index) ? @curdate.sub_days(1).add_weeks(@length) : @curdate.x_weeks_from_day(@length - 1, @day_index)
|
747
|
-
@constructs << DateConstruct.new(:date => d, :comp_start => @pos, :comp_end => @pos += 3, :found_in =>
|
744
|
+
@constructs << DateConstruct.new(:date => d, :comp_start => @pos, :comp_end => @pos += 3, :found_in => __method__)
|
748
745
|
end
|
749
746
|
|
750
747
|
def match_x_dayname_from_this
|
@@ -752,7 +749,7 @@ module Nickel
|
|
752
749
|
end
|
753
750
|
|
754
751
|
def found_x_dayname_from_this
|
755
|
-
dc = DateConstruct.new(:date => @curdate.this(@day_index).add_weeks(@length), :comp_start => @pos, :found_in =>
|
752
|
+
dc = DateConstruct.new(:date => @curdate.this(@day_index).add_weeks(@length), :comp_start => @pos, :found_in => __method__)
|
756
753
|
if @components[@post+4] == "one" || ZDate.days_of_week.index(@components[@pos+4]) # talk about redundant (2 tuesdays from this one, 2 tuesdays from this tuesday)
|
757
754
|
dc.comp_end = @pos += 4
|
758
755
|
else
|
@@ -766,7 +763,7 @@ module Nickel
|
|
766
763
|
end
|
767
764
|
|
768
765
|
def found_x_dayname_from_next
|
769
|
-
dc = DateConstruct.new(:date => @curdate.next(@day_index).add_weeks(@length), :comp_start => @pos, :found_in =>
|
766
|
+
dc = DateConstruct.new(:date => @curdate.next(@day_index).add_weeks(@length), :comp_start => @pos, :found_in => __method__)
|
770
767
|
if @components[@post+4] == "one" || ZDate.days_of_week.index(@components[@pos+4]) # talk about redundant (2 tuesdays from next one, 2 tuesdays from next tuesday)
|
771
768
|
dc.comp_end = @pos += 4
|
772
769
|
else
|
@@ -774,29 +771,29 @@ module Nickel
|
|
774
771
|
end
|
775
772
|
@constructs << dc
|
776
773
|
end
|
777
|
-
|
774
|
+
|
778
775
|
def match_x_minutes_from_now
|
779
|
-
@components[@pos]
|
776
|
+
ConstructFinder.digits_only?(@components[@pos]) && @components[@pos+1] =~ /minutes?/ && @components[@pos+2] == "from" && @components[@pos+3] =~ /^(today|now)$/ && @length = @components[@pos].to_i
|
780
777
|
end
|
781
778
|
|
782
779
|
def found_x_minutes_from_now
|
783
780
|
date = nil # define out of scope of block
|
784
781
|
time = @curtime.add_minutes(@length) {|days_to_increment| date = @curdate.add_days(days_to_increment)}
|
785
|
-
@constructs << DateConstruct.new(:date => date, :comp_start => @pos, :comp_end => @pos + 4, :found_in =>
|
786
|
-
@constructs << TimeConstruct.new(:time => time, :comp_start => @pos, :comp_end => @pos += 4, :found_in =>
|
782
|
+
@constructs << DateConstruct.new(:date => date, :comp_start => @pos, :comp_end => @pos + 4, :found_in => __method__)
|
783
|
+
@constructs << TimeConstruct.new(:time => time, :comp_start => @pos, :comp_end => @pos += 4, :found_in => __method__)
|
787
784
|
end
|
788
785
|
|
789
786
|
def match_x_hours_from_now
|
790
|
-
@components[@pos]
|
787
|
+
ConstructFinder.digits_only?(@components[@pos]) && @components[@pos+1] =~ /hours?/ && @components[@pos+2] == "from" && @components[@pos+3] =~ /^(today|now)$/ && @length = @components[@pos].to_i
|
791
788
|
end
|
792
789
|
|
793
790
|
def found_x_hours_from_now
|
794
791
|
date = nil
|
795
792
|
time = @curtime.add_hours(@length) {|days_to_increment| date = @curdate.add_days(days_to_increment)}
|
796
|
-
@constructs << DateConstruct.new(:date => date, :comp_start => @pos, :comp_end => @pos + 4, :found_in =>
|
797
|
-
@constructs << TimeConstruct.new(:time => time, :comp_start => @pos, :comp_end => @pos += 4, :found_in =>
|
793
|
+
@constructs << DateConstruct.new(:date => date, :comp_start => @pos, :comp_end => @pos + 4, :found_in => __method__)
|
794
|
+
@constructs << TimeConstruct.new(:time => time, :comp_start => @pos, :comp_end => @pos += 4, :found_in => __method__)
|
798
795
|
end
|
799
|
-
|
796
|
+
|
800
797
|
def match_ordinal_dayname
|
801
798
|
@components[@pos]=~/(1st|2nd|3rd|4th|5th)/ && (@day_index = ZDate.days_of_week.index(@components[@pos+1])) && @week_num = @components[@pos].to_i # last saturday
|
802
799
|
end
|
@@ -806,7 +803,7 @@ module Nickel
|
|
806
803
|
end
|
807
804
|
|
808
805
|
def found_ordinal_dayname_this_month
|
809
|
-
@constructs << DateConstruct.new(:date => @curdate.ordinal_dayindex(@week_num, @day_index), :comp_start => @pos, :comp_end => @pos += 3, :found_in =>
|
806
|
+
@constructs << DateConstruct.new(:date => @curdate.ordinal_dayindex(@week_num, @day_index), :comp_start => @pos, :comp_end => @pos += 3, :found_in => __method__)
|
810
807
|
end
|
811
808
|
|
812
809
|
def match_ordinal_dayname_next_month
|
@@ -814,7 +811,7 @@ module Nickel
|
|
814
811
|
end
|
815
812
|
|
816
813
|
def found_ordinal_dayname_next_month
|
817
|
-
@constructs << DateConstruct.new(:date => @curdate.add_months(1).ordinal_dayindex(@week_num, @day_index), :comp_start => @pos, :comp_end => @pos += 3, :found_in =>
|
814
|
+
@constructs << DateConstruct.new(:date => @curdate.add_months(1).ordinal_dayindex(@week_num, @day_index), :comp_start => @pos, :comp_end => @pos += 3, :found_in => __method__)
|
818
815
|
end
|
819
816
|
|
820
817
|
def match_ordinal_dayname_monthname
|
@@ -822,9 +819,9 @@ module Nickel
|
|
822
819
|
end
|
823
820
|
|
824
821
|
def found_ordinal_dayname_monthname
|
825
|
-
@constructs << DateConstruct.new(:date => @curdate.jump_to_month(@month_index + 1).ordinal_dayindex(@week_num, @day_index), :comp_start => @pos, :comp_end => @pos += 2, :found_in =>
|
822
|
+
@constructs << DateConstruct.new(:date => @curdate.jump_to_month(@month_index + 1).ordinal_dayindex(@week_num, @day_index), :comp_start => @pos, :comp_end => @pos += 2, :found_in => __method__)
|
826
823
|
end
|
827
|
-
|
824
|
+
|
828
825
|
|
829
826
|
def match_ordinal_this_month
|
830
827
|
@components[@pos]=~/(0?[1-9]|[12][0-9]|3[01])(st|nd|rd|th)/ && @components[@pos+1] == 'this' && @components[@pos+2] = 'month' && @length = @components[@pos].to_i # 28th this month
|
@@ -835,20 +832,20 @@ module Nickel
|
|
835
832
|
end
|
836
833
|
|
837
834
|
def found_ordinal_this_month
|
838
|
-
if
|
835
|
+
if @curdate.day > @length
|
839
836
|
# e.g. it is the 30th of the month and a user types "1st of the month", they mean "first of next month"
|
840
837
|
date = @curdate.add_months(1).beginning_of_month.add_days(@length - 1)
|
841
838
|
else
|
842
839
|
date = @curdate.beginning_of_month.add_days(@length - 1)
|
843
840
|
end
|
844
|
-
@constructs << DateConstruct.new(:date => date, :comp_start => @pos, :comp_end => @pos += 2, :found_in =>
|
841
|
+
@constructs << DateConstruct.new(:date => date, :comp_start => @pos, :comp_end => @pos += 2, :found_in => __method__)
|
845
842
|
end
|
846
843
|
|
847
844
|
def found_ordinal_next_month
|
848
|
-
@constructs << DateConstruct.new(:date => @curdate.add_months(1).beginning_of_month.add_days(@length - 1), :comp_start => @pos, :comp_end => @pos += 2, :found_in =>
|
845
|
+
@constructs << DateConstruct.new(:date => @curdate.add_months(1).beginning_of_month.add_days(@length - 1), :comp_start => @pos, :comp_end => @pos += 2, :found_in => __method__)
|
849
846
|
end
|
850
|
-
|
851
|
-
|
847
|
+
|
848
|
+
|
852
849
|
def match_first_day
|
853
850
|
@components[@pos] == "1st" && @components[@pos+1] == "day" # 1st day
|
854
851
|
end
|
@@ -858,7 +855,7 @@ module Nickel
|
|
858
855
|
end
|
859
856
|
|
860
857
|
def found_first_day_this_month
|
861
|
-
@constructs << DateConstruct.new(:date => @curdate.beginning_of_month, :comp_start => @pos, :comp_end => @pos += 3, :found_in =>
|
858
|
+
@constructs << DateConstruct.new(:date => @curdate.beginning_of_month, :comp_start => @pos, :comp_end => @pos += 3, :found_in => __method__)
|
862
859
|
end
|
863
860
|
|
864
861
|
def match_first_day_next_month
|
@@ -866,7 +863,7 @@ module Nickel
|
|
866
863
|
end
|
867
864
|
|
868
865
|
def found_first_day_next_month
|
869
|
-
@constructs << DateConstruct.new(:date => @curdate.add_months(1).beginning_of_month, :comp_start => @pos, :comp_end => @pos += 3, :found_in =>
|
866
|
+
@constructs << DateConstruct.new(:date => @curdate.add_months(1).beginning_of_month, :comp_start => @pos, :comp_end => @pos += 3, :found_in => __method__)
|
870
867
|
end
|
871
868
|
|
872
869
|
def match_first_day_monthname
|
@@ -874,7 +871,7 @@ module Nickel
|
|
874
871
|
end
|
875
872
|
|
876
873
|
def found_first_day_monthname
|
877
|
-
@constructs << DateConstruct.new(:date => @curdate.jump_to_month(@month_index + 1), :comp_start => @pos, :comp_end => @pos += 2, :found_in =>
|
874
|
+
@constructs << DateConstruct.new(:date => @curdate.jump_to_month(@month_index + 1), :comp_start => @pos, :comp_end => @pos += 2, :found_in => __method__)
|
878
875
|
end
|
879
876
|
|
880
877
|
def match_last_day
|
@@ -886,7 +883,7 @@ module Nickel
|
|
886
883
|
end
|
887
884
|
|
888
885
|
def found_last_day_this_month
|
889
|
-
@constructs << DateConstruct.new(:date => @curdate.end_of_month, :comp_start => @pos, :comp_end => @pos += 3, :found_in =>
|
886
|
+
@constructs << DateConstruct.new(:date => @curdate.end_of_month, :comp_start => @pos, :comp_end => @pos += 3, :found_in => __method__)
|
890
887
|
end
|
891
888
|
|
892
889
|
def match_last_day_next_month
|
@@ -894,7 +891,7 @@ module Nickel
|
|
894
891
|
end
|
895
892
|
|
896
893
|
def found_last_day_next_month
|
897
|
-
@constructs << DateConstruct.new(:date => @curdate.add_months(1).end_of_month, :comp_start => @pos, :comp_end => @pos += 3, :found_in =>
|
894
|
+
@constructs << DateConstruct.new(:date => @curdate.add_months(1).end_of_month, :comp_start => @pos, :comp_end => @pos += 3, :found_in => __method__)
|
898
895
|
end
|
899
896
|
|
900
897
|
def match_last_day_monthname
|
@@ -902,27 +899,27 @@ module Nickel
|
|
902
899
|
end
|
903
900
|
|
904
901
|
def found_last_day_monthname
|
905
|
-
@constructs << DateConstruct.new(:date => @curdate.jump_to_month(@month_index + 1).end_of_month, :comp_start => @pos, :comp_end => @pos += 2, :found_in =>
|
902
|
+
@constructs << DateConstruct.new(:date => @curdate.jump_to_month(@month_index + 1).end_of_month, :comp_start => @pos, :comp_end => @pos += 2, :found_in => __method__)
|
906
903
|
end
|
907
|
-
|
904
|
+
|
908
905
|
def match_at
|
909
906
|
@components[@pos]=="at"
|
910
907
|
end
|
911
908
|
|
912
909
|
def match_at_time
|
913
|
-
@components[@pos+1] && @time1 = @components[@pos+1]
|
910
|
+
@components[@pos+1] && @time1 = ZTime.interpret(@components[@pos+1])
|
914
911
|
end
|
915
912
|
|
916
913
|
def match_at_time_through_time
|
917
|
-
@components[@pos+2] =~ /^(to|until|through)$/ && @components[@pos+3] && @time2 = @components[@pos+3]
|
914
|
+
@components[@pos+2] =~ /^(to|until|through)$/ && @components[@pos+3] && @time2 = ZTime.interpret(@components[@pos+3])
|
918
915
|
end
|
919
916
|
|
920
917
|
def found_at_time_through_time
|
921
|
-
@constructs << TimeSpanConstruct.new(:start_time => @time1, :end_time => @time2, :comp_start => @pos, :comp_end => @pos += 3, :found_in =>
|
918
|
+
@constructs << TimeSpanConstruct.new(:start_time => @time1, :end_time => @time2, :comp_start => @pos, :comp_end => @pos += 3, :found_in => __method__)
|
922
919
|
end
|
923
920
|
|
924
921
|
def found_at_time
|
925
|
-
@constructs << TimeConstruct.new(:time => @time1, :comp_start => @pos, :comp_end => @pos += 1, :found_in =>
|
922
|
+
@constructs << TimeConstruct.new(:time => @time1, :comp_start => @pos, :comp_end => @pos += 1, :found_in => __method__)
|
926
923
|
end
|
927
924
|
|
928
925
|
def match_all_day
|
@@ -930,9 +927,9 @@ module Nickel
|
|
930
927
|
end
|
931
928
|
|
932
929
|
def found_all_day
|
933
|
-
@constructs << TimeConstruct.new(:time => nil, :comp_start => @pos, :comp_end => @pos += 1, :found_in =>
|
930
|
+
@constructs << TimeConstruct.new(:time => nil, :comp_start => @pos, :comp_end => @pos += 1, :found_in => __method__)
|
934
931
|
end
|
935
|
-
|
932
|
+
|
936
933
|
def match_tomorrow
|
937
934
|
@components[@pos]=="tomorrow"
|
938
935
|
end
|
@@ -946,21 +943,21 @@ module Nickel
|
|
946
943
|
end
|
947
944
|
|
948
945
|
def found_tomorrow_through_dayname
|
949
|
-
@constructs << DateSpanConstruct.new(:start_date => @curdate.add_days(1), :end_date => @curdate.add_days(1).this(@day_index), :comp_start => @pos, :comp_end => @pos += 2, :found_in =>
|
946
|
+
@constructs << DateSpanConstruct.new(:start_date => @curdate.add_days(1), :end_date => @curdate.add_days(1).this(@day_index), :comp_start => @pos, :comp_end => @pos += 2, :found_in => __method__)
|
950
947
|
end
|
951
948
|
|
952
949
|
def match_tomorrow_through_date
|
953
|
-
@date1 = @components[@pos+2]
|
950
|
+
@date1 = ZDate.interpret(@components[@pos+2], @curdate) # tomorrow until 9/21
|
954
951
|
end
|
955
952
|
|
956
953
|
def found_tomorrow_through_date
|
957
|
-
@constructs << DateSpanConstruct.new(:start_date => @curdate.add_days(1), :end_date => @date1, :comp_start => @pos, :comp_end => @pos += 2, :found_in =>
|
954
|
+
@constructs << DateSpanConstruct.new(:start_date => @curdate.add_days(1), :end_date => @date1, :comp_start => @pos, :comp_end => @pos += 2, :found_in => __method__)
|
958
955
|
end
|
959
956
|
|
960
957
|
def found_tomorrow
|
961
|
-
@constructs << DateConstruct.new(:date => @curdate.add_days(1), :comp_start => @pos, :comp_end => @pos, :found_in =>
|
958
|
+
@constructs << DateConstruct.new(:date => @curdate.add_days(1), :comp_start => @pos, :comp_end => @pos, :found_in => __method__)
|
962
959
|
end
|
963
|
-
|
960
|
+
|
964
961
|
def match_now
|
965
962
|
@components[@pos]=="today" || @components[@pos]=="now"
|
966
963
|
end
|
@@ -974,7 +971,7 @@ module Nickel
|
|
974
971
|
end
|
975
972
|
|
976
973
|
def found_now_through_dayname
|
977
|
-
@constructs << DateSpanConstruct.new(:start_date => @curdate, :end_date => @curdate.this(@day_index), :comp_start => @pos, :comp_end => @pos += 2, :found_in =>
|
974
|
+
@constructs << DateSpanConstruct.new(:start_date => @curdate, :end_date => @curdate.this(@day_index), :comp_start => @pos, :comp_end => @pos += 2, :found_in => __method__)
|
978
975
|
end
|
979
976
|
|
980
977
|
# redundant!! preprocess this out of here!
|
@@ -984,15 +981,15 @@ module Nickel
|
|
984
981
|
|
985
982
|
# redundant!! preprocess this out of here!
|
986
983
|
def found_now_through_following_dayname
|
987
|
-
@constructs << DateSpanConstruct.new(:start_date => @curdate, :end_date => @curdate.this(@day_index), :comp_start => @pos, :comp_end => @pos += 3, :found_in =>
|
984
|
+
@constructs << DateSpanConstruct.new(:start_date => @curdate, :end_date => @curdate.this(@day_index), :comp_start => @pos, :comp_end => @pos += 3, :found_in => __method__)
|
988
985
|
end
|
989
986
|
|
990
987
|
def match_now_through_date
|
991
|
-
@date1 = @components[@pos+2]
|
988
|
+
@date1 = ZDate.interpret(@components[@pos+2], @curdate) # now until 9/21
|
992
989
|
end
|
993
990
|
|
994
991
|
def found_now_through_date
|
995
|
-
@constructs << DateSpanConstruct.new(:start_date => @curdate, :end_date => @date1, :comp_start => @pos, :comp_end => @pos += 2, :found_in =>
|
992
|
+
@constructs << DateSpanConstruct.new(:start_date => @curdate, :end_date => @date1, :comp_start => @pos, :comp_end => @pos += 2, :found_in => __method__)
|
996
993
|
end
|
997
994
|
|
998
995
|
def match_now_through_tomorrow
|
@@ -1000,7 +997,7 @@ module Nickel
|
|
1000
997
|
end
|
1001
998
|
|
1002
999
|
def found_now_through_tomorrow
|
1003
|
-
@constructs << DateSpanConstruct.new(:start_date => @curdate, :end_date => @curdate.add_days(1), :comp_start => @pos, :comp_end => @pos += 2, :found_in =>
|
1000
|
+
@constructs << DateSpanConstruct.new(:start_date => @curdate, :end_date => @curdate.add_days(1), :comp_start => @pos, :comp_end => @pos += 2, :found_in => __method__)
|
1004
1001
|
end
|
1005
1002
|
|
1006
1003
|
def match_now_through_next_dayname
|
@@ -1008,36 +1005,36 @@ module Nickel
|
|
1008
1005
|
end
|
1009
1006
|
|
1010
1007
|
def found_now_through_next_dayname
|
1011
|
-
@constructs << DateSpanConstruct.new(:start_date => @curdate, :end_date => @curdate.next(@day_index), :comp_start => @pos, :comp_end => @pos += 3, :found_in =>
|
1008
|
+
@constructs << DateSpanConstruct.new(:start_date => @curdate, :end_date => @curdate.next(@day_index), :comp_start => @pos, :comp_end => @pos += 3, :found_in => __method__)
|
1012
1009
|
end
|
1013
1010
|
|
1014
1011
|
def found_now
|
1015
|
-
@constructs << DateConstruct.new(:date => @curdate, :comp_start => @pos, :comp_end => @pos, :found_in =>
|
1012
|
+
@constructs << DateConstruct.new(:date => @curdate, :comp_start => @pos, :comp_end => @pos, :found_in => __method__)
|
1016
1013
|
end
|
1017
|
-
|
1014
|
+
|
1018
1015
|
def match_dayname
|
1019
1016
|
@day_index = ZDate.days_of_week.index(@components[@pos])
|
1020
1017
|
end
|
1021
1018
|
|
1022
1019
|
def match_dayname_the_ordinal
|
1023
|
-
@components[@pos+1] == "the" && @date1 = @components[@pos+2]
|
1020
|
+
@components[@pos+1] == "the" && @date1 = ZDate.interpret(@components[@pos+2], @curdate) # if "tue the 23rd"
|
1024
1021
|
end
|
1025
1022
|
|
1026
1023
|
def found_dayname_the_ordinal
|
1027
1024
|
# user may have specified "monday the 2nd" while in the previous month, so first check if dayname matches date.dayname, if it doesn't increment by a month and check again
|
1028
1025
|
if @date1.dayname == @components[@pos] || ((tmp = @date1.add_months(1)) && tmp.dayname == @components[@pos] && @date1 = tmp)
|
1029
|
-
@constructs << DateConstruct.new(:date => @date1, :comp_start => @pos, :comp_end => @pos += 2, :found_in =>
|
1026
|
+
@constructs << DateConstruct.new(:date => @date1, :comp_start => @pos, :comp_end => @pos += 2, :found_in => __method__)
|
1030
1027
|
end
|
1031
1028
|
end
|
1032
1029
|
|
1033
1030
|
def match_dayname_x_weeks_from_this
|
1034
|
-
@components[@pos+1] && @components[@pos+1]
|
1031
|
+
@components[@pos+1] && ConstructFinder.digits_only?(@components[@pos+1]) && @components[@pos+2] =~ /\bweeks?\b/ && @components[@pos+3] =~ /\b(from)|(after)/ && @components[@pos+4] == "this" && @length = @components[@pos+1] # "monday two weeks from this
|
1035
1032
|
end
|
1036
1033
|
|
1037
1034
|
def found_dayname_x_weeks_from_this
|
1038
|
-
dc = DateConstruct.new(:date => @curdate.this(@dayindex).add_weeks(@length), :comp_start => @pos, :found_in =>
|
1035
|
+
dc = DateConstruct.new(:date => @curdate.this(@dayindex).add_weeks(@length), :comp_start => @pos, :found_in => __method__)
|
1039
1036
|
if ZDate.days_of_week.include?(@components[@pos+5]) #redundant
|
1040
|
-
dc.comp_end = @pos += 5
|
1037
|
+
dc.comp_end = @pos += 5
|
1041
1038
|
else
|
1042
1039
|
dc.comp_end = @pos += 4
|
1043
1040
|
end
|
@@ -1045,13 +1042,13 @@ module Nickel
|
|
1045
1042
|
end
|
1046
1043
|
|
1047
1044
|
def match_dayname_x_weeks_from_next
|
1048
|
-
@components[@pos+1] && @components[@pos+1]
|
1045
|
+
@components[@pos+1] && ConstructFinder.digits_only?(@components[@pos+1]) && @components[@pos+2] =~ /\bweeks?\b/ && @components[@pos+3] =~ /\b(from)|(after)/ && @components[@pos+4] == "next" && @length = @components[@pos+1] # "monday two weeks from this
|
1049
1046
|
end
|
1050
1047
|
|
1051
1048
|
def found_dayname_x_weeks_from_next
|
1052
|
-
dc = DateConstruct.new(:date => @curdate.next(@dayindex).add_weeks(@length), :comp_start => @pos, :found_in =>
|
1049
|
+
dc = DateConstruct.new(:date => @curdate.next(@dayindex).add_weeks(@length), :comp_start => @pos, :found_in => __method__)
|
1053
1050
|
if ZDate.days_of_week.include?(@components[@pos+5]) #redundant
|
1054
|
-
dc.comp_end = @pos += 5
|
1051
|
+
dc.comp_end = @pos += 5
|
1055
1052
|
else
|
1056
1053
|
dc.comp_end = @pos += 4
|
1057
1054
|
end
|
@@ -1061,10 +1058,10 @@ module Nickel
|
|
1061
1058
|
# redundant, same as found_this_dayname
|
1062
1059
|
def found_dayname
|
1063
1060
|
day_to_add = @curdate.this(@day_index)
|
1064
|
-
@constructs << DateConstruct.new(:date => day_to_add, :comp_start => @pos, :comp_end => @pos, :found_in =>
|
1061
|
+
@constructs << DateConstruct.new(:date => day_to_add, :comp_start => @pos, :comp_end => @pos, :found_in => __method__)
|
1065
1062
|
while @components[@pos+1] && @day_index = ZDate.days_of_week.index(@components[@pos+1])
|
1066
1063
|
# note @pos gets incremented here:
|
1067
|
-
@constructs << DateConstruct.new(:date => day_to_add = day_to_add.this(@day_index), :comp_start => @pos + 1, :comp_end => @pos += 1, :found_in =>
|
1064
|
+
@constructs << DateConstruct.new(:date => day_to_add = day_to_add.this(@day_index), :comp_start => @pos + 1, :comp_end => @pos += 1, :found_in => __method__)
|
1068
1065
|
end
|
1069
1066
|
end
|
1070
1067
|
|
@@ -1074,8 +1071,8 @@ module Nickel
|
|
1074
1071
|
|
1075
1072
|
def found_through_monthname
|
1076
1073
|
# this is really a wrapper, we don't know when the start date is, so make sure @constructs gets wrapper first, as date constructs always have to appear after wrapper
|
1077
|
-
@constructs << WrapperConstruct.new(:wrapper_type => 1, :comp_start => @pos, :comp_end => @pos + 1, :found_in =>
|
1078
|
-
@constructs << DateConstruct.new(:date => @curdate.jump_to_month(@month_index + 1).sub_days(1), :comp_start => @pos, :comp_end => @pos += 1, :found_in =>
|
1074
|
+
@constructs << WrapperConstruct.new(:wrapper_type => 1, :comp_start => @pos, :comp_end => @pos + 1, :found_in => __method__)
|
1075
|
+
@constructs << DateConstruct.new(:date => @curdate.jump_to_month(@month_index + 1).sub_days(1), :comp_start => @pos, :comp_end => @pos += 1, :found_in => __method__)
|
1079
1076
|
end
|
1080
1077
|
|
1081
1078
|
def match_monthname
|
@@ -1086,7 +1083,7 @@ module Nickel
|
|
1086
1083
|
def found_monthname
|
1087
1084
|
sd = @curdate.jump_to_month(@month_index + 1)
|
1088
1085
|
ed = sd.end_of_month
|
1089
|
-
@constructs << DateSpanConstruct.new(:start_date => sd, :end_date => ed, :comp_start => @pos, :comp_end => @pos, :found_in =>
|
1086
|
+
@constructs << DateSpanConstruct.new(:start_date => sd, :end_date => ed, :comp_start => @pos, :comp_end => @pos, :found_in => __method__)
|
1090
1087
|
end
|
1091
1088
|
|
1092
1089
|
|
@@ -1096,7 +1093,7 @@ module Nickel
|
|
1096
1093
|
|
1097
1094
|
def found_start
|
1098
1095
|
#wrapper_type 0 is a start wrapper
|
1099
|
-
@constructs << WrapperConstruct.new(:wrapper_type => 0, :comp_start => @pos, :comp_end => @pos, :found_in =>
|
1096
|
+
@constructs << WrapperConstruct.new(:wrapper_type => 0, :comp_start => @pos, :comp_end => @pos, :found_in => __method__)
|
1100
1097
|
end
|
1101
1098
|
|
1102
1099
|
def match_through
|
@@ -1105,40 +1102,50 @@ module Nickel
|
|
1105
1102
|
|
1106
1103
|
def found_through
|
1107
1104
|
#wrapper_type 1 is an end wrapper
|
1108
|
-
@constructs << WrapperConstruct.new(:wrapper_type => 1, :comp_start => @pos, :comp_end => @pos, :found_in =>
|
1105
|
+
@constructs << WrapperConstruct.new(:wrapper_type => 1, :comp_start => @pos, :comp_end => @pos, :found_in => __method__)
|
1109
1106
|
end
|
1110
1107
|
|
1111
1108
|
def match_time
|
1112
|
-
@time1 = @components[@pos]
|
1109
|
+
@time1 = ZTime.interpret(@components[@pos])
|
1113
1110
|
end
|
1114
1111
|
|
1115
1112
|
def match_time_through_time
|
1116
|
-
@components[@pos+1] =~ /^(to|through)$/ && @time2 = @components[@pos+2]
|
1113
|
+
@components[@pos+1] =~ /^(to|through)$/ && @time2 = ZTime.interpret(@components[@pos+2])
|
1117
1114
|
end
|
1118
1115
|
|
1119
1116
|
def found_time_through_time
|
1120
|
-
@constructs << TimeSpanConstruct.new(:start_time => @time1, :end_time => @time2, :comp_start => @pos, :comp_end => @pos += 2, :found_in =>
|
1117
|
+
@constructs << TimeSpanConstruct.new(:start_time => @time1, :end_time => @time2, :comp_start => @pos, :comp_end => @pos += 2, :found_in => __method__)
|
1121
1118
|
end
|
1122
1119
|
|
1123
1120
|
def found_time
|
1124
|
-
@constructs << TimeConstruct.new(:time => @time1, :comp_start => @pos, :comp_end => @pos, :found_in =>
|
1125
|
-
match = true
|
1121
|
+
@constructs << TimeConstruct.new(:time => @time1, :comp_start => @pos, :comp_end => @pos, :found_in => __method__)
|
1126
1122
|
end
|
1127
1123
|
|
1128
1124
|
def match_date
|
1129
|
-
@date1 = @components[@pos]
|
1125
|
+
@date1 = ZDate.interpret(@components[@pos], @curdate)
|
1130
1126
|
end
|
1131
1127
|
|
1132
1128
|
def match_date_through_date
|
1133
|
-
@components[@pos+1] =~ /^(through|to|until)$/ && @date2 = @components[@pos+2]
|
1129
|
+
@components[@pos+1] =~ /^(through|to|until)$/ && @date2 = ZDate.interpret(@components[@pos+2], @curdate)
|
1134
1130
|
end
|
1135
1131
|
|
1136
1132
|
def found_date_through_date
|
1137
|
-
@constructs << DateSpanConstruct.new(:start_date => @date1, :end_date => @date2, :comp_start => @pos, :comp_end => @pos += 2, :found_in =>
|
1133
|
+
@constructs << DateSpanConstruct.new(:start_date => @date1, :end_date => @date2, :comp_start => @pos, :comp_end => @pos += 2, :found_in => __method__)
|
1138
1134
|
end
|
1139
1135
|
|
1140
1136
|
def found_date
|
1141
|
-
@constructs << DateConstruct.new(:date => @date1, :comp_start => @pos, :comp_end => @pos, :found_in =>
|
1137
|
+
@constructs << DateConstruct.new(:date => @date1, :comp_start => @pos, :comp_end => @pos, :found_in => __method__)
|
1138
|
+
end
|
1139
|
+
|
1140
|
+
class << self
|
1141
|
+
def digits_only?(str)
|
1142
|
+
str =~ /^\d+$/ #no characters other than digits
|
1143
|
+
end
|
1144
|
+
|
1145
|
+
# valid hour, 24hour, and minute could use some cleaning
|
1146
|
+
def ordinal_only?(str)
|
1147
|
+
str =~ %r{^(0?[1-9]|[12][0-9]|3[01])(?:st|nd|rd|th)?$}
|
1148
|
+
end
|
1142
1149
|
end
|
1143
1150
|
end # END class ConstructFinder
|
1144
1151
|
end
|