Class: Quando::Parser
- Inherits:
-
Object
- Object
- Quando::Parser
- Defined in:
- lib/quando/parser.rb
Instance Method Summary collapse
- #config ⇒ Quando::Config
- #configure {|@config ||= Quando.config.dup| ... } ⇒ Quando::Parser
-
#initialize ⇒ Parser
constructor
A new instance of Parser.
- #parse(text_date) ⇒ Date?
Constructor Details
#initialize ⇒ Parser
Returns a new instance of Parser.
6 7 8 |
# File 'lib/quando/parser.rb', line 6 def initialize @config = nil end |
Instance Method Details
#config ⇒ Quando::Config
17 18 19 |
# File 'lib/quando/parser.rb', line 17 def config @config || Quando.config end |
#configure {|@config ||= Quando.config.dup| ... } ⇒ Quando::Parser
11 12 13 14 |
# File 'lib/quando/parser.rb', line 11 def configure yield(@config ||= Quando.config.dup) self end |
#parse(text_date) ⇒ Date?
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 |