Class: Kit::DateParser

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

Overview

Parses dates as they appear in the results table

Instance Method Summary collapse

Constructor Details

#initializeDateParser

Creates a new DateParser



7
8
9
# File 'lib/kit/date_parser.rb', line 7

def initialize
  @date_format = '%m/%d/%Y'
end

Instance Method Details

#parse(element) ⇒ Date?

Returns the first date, if any, in the given element‘s text

Parameters:

  • element (#text)

    an element with text

Returns:

  • (Date)

    if the given element contains a parseable date

  • (nil)

    if the given element contains no parseable dates



17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/kit/date_parser.rb', line 17

def parse(element)
  part_with_date = element.text.split(' ').find do |date_string|
    begin
      string_to_date(date_string)
    rescue ArgumentError
    end
  end

  if part_with_date
    string_to_date(part_with_date)
  end
end