Class: EventNlp
Instance Attribute Summary collapse
-
#params ⇒ Object
Returns the value of attribute params.
Instance Method Summary collapse
-
#initialize(now = Time.now, params: {leap: :back}, debug: false) ⇒ EventNlp
constructor
A new instance of EventNlp.
- #parse(raws) ⇒ Object
-
#project(s, year: @now.year) ⇒ Object
returns an Array object of dates, projected from a recurring event.
Constructor Details
#initialize(now = Time.now, params: {leap: :back}, debug: false) ⇒ EventNlp
Returns a new instance of EventNlp.
28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/event_nlp.rb', line 28 def initialize(now=Time.now, params: {leap: :back}, debug: false) super() @debug = debug @now = now @params = params expressions(@params) end |
Instance Attribute Details
#params ⇒ Object
Returns the value of attribute params.
26 27 28 |
# File 'lib/event_nlp.rb', line 26 def params @params end |
Instance Method Details
#parse(raws) ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/event_nlp.rb', line 41 def parse(raws) s = filter_irregular(raws) #----------------------------------------------------------- @params[:input] = s puts 'parse: about to execute run_route' if @debug r = run_route(s) return unless r.is_a? Hash OpenStruct.new({input: s}.merge r) end |
#project(s, year: @now.year) ⇒ Object
returns an Array object of dates, projected from a recurring event
Example parameters:
s: ‘Council Tax 30th Monthly’ s: ‘Council Tax 30th Monthly until 2nd October’
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 |
# File 'lib/event_nlp.rb', line 64 def project(s, year: @now.year) s2, raw_end_date = s.split(/ +\buntil\b +/) end_date = if raw_end_date then EventNlp.new().parse(raw_end_date).date else puts 'before date parse' if @debug (Date.parse('1 Jan ' + (year+1).to_s) - 1).to_time end puts 'project/end_date: ' + end_date.inspect if @debug # filter the input to ensure validity r0 = parse s2 puts 'project/r0: ' + r0.inspect if @debug r = parse r0.input puts 'project/r: ' + r.inspect if @debug dates = [] now = @now if @debug then puts 'r.date: ' + r.date.inspect puts 'r.input: ' + r.input.inspect puts 'EventNlp.new(r.date+1).parse(r.input).date: ' + \ EventNlp.new(r.date+1).parse(r.input).date.inspect end return [r.date] if (r.date == EventNlp.new(r.date+1, debug: @debug).parse(r.input).date) #year.to_i while r.date <= end_date do puts 'project/r.date: ' + r.date.inspect if @debug dates << r.date @now = if r.recurring == 'month' then (r.date.to_date >> 1).to_time #elsif r.recurring == 'weekly' else r.date + 1 end puts '@now: ' + @now.inspect if @debug #@now = r.date + 1 r = parse(r.input) end @now = now return dates end |