Class: Datte::DateParser

Inherits:
Object
  • Object
show all
Defined in:
lib/datte/date_parser.rb

Instance Method Summary collapse

Constructor Details

#initialize(body, options = {}) ⇒ DateParser

Returns a new instance of DateParser.



3
4
5
6
7
# File 'lib/datte/date_parser.rb', line 3

def initialize(body, options = {})
  @body = body
  @options = options
  @date = Dattetime.new
end

Instance Method Details

#parseObject



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/datte/date_parser.rb', line 9

def parse
  ABSOLUTE_DATES.each do |matcher|
    if md = @body.match(matcher)
      @date.update_date(md)
      break
    end
  end

  ABSOLUTE_TIMES.each do |matcher|
    if md = @body.match(matcher)
      @date.update_time(md)
      p @date
      break
    end
  end

  NOUNS.each do |matcher_s, method|
    matcher = Regexp.new(matcher_s.to_s)
    if md = @body.match(matcher)
      eval(method)
      break
    end
  end

  AFTERS.each do |matcher|
    if md = @body.match(matcher)
      @date.after(md)
      break
    end
  end

  return @date.to_datetime
end