Class: Quando::Parser

Inherits:
Object
  • Object
show all
Defined in:
lib/quando/parser.rb

Instance Method Summary collapse

Constructor Details

#initializeParser

Returns a new instance of Parser.



6
7
8
# File 'lib/quando/parser.rb', line 6

def initialize
  @config = nil
end

Instance Method Details

#configQuando::Config

Returns:



17
18
19
# File 'lib/quando/parser.rb', line 17

def config
  @config || Quando.config
end

#configure {|@config ||= Quando.config.dup| ... } ⇒ Quando::Parser

Yields:

Returns:



11
12
13
14
# File 'lib/quando/parser.rb', line 11

def configure
  yield(@config ||= Quando.config.dup)
  self
end

#parse(text_date) ⇒ Date?

Parameters:

  • text_date (String)

Returns:

  • (Date, nil)


23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/quando/parser.rb', line 23

def parse(text_date)
  config.formats.each do |regexp|
    @date_parts = text_date.match(regexp)
    next unless @date_parts

    @current_format = regexp
    year, month, day = detect_year, detect_month, detect_day
    next unless (year && month && day)

    return Date.new(year, month, day)
  end

  nil
end