class Kit::DateParser
Parses dates as they appear in the results table
Public Class Methods
new()
click to toggle source
Creates a new DateParser
# File lib/kit/date_parser.rb, line 7 def initialize @date_format = '%m/%d/%Y' end
Public Instance Methods
parse(element)
click to toggle source
Returns the first date, if any, in the given element
's text
@param element [#text] an element with text
@return [Date] if the given element
contains a parseable date @return [nil] if the given element
contains no parseable dates
# 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
Private Instance Methods
string_to_date(string)
click to toggle source
# File lib/kit/date_parser.rb, line 32 def string_to_date(string) Date.strptime(string, @date_format) end