Class: Lakes::Texas::FishingReportParser

Inherits:
Object
  • Object
show all
Includes:
Helper
Defined in:
lib/lakes/texas/fishing_report_parser.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Helper

#cleanup_data, #cleanup_raw_text, #convert_relative_href, #http_get

Constructor Details

#initialize(text) ⇒ FishingReportParser

Returns a new instance of FishingReportParser.



12
13
14
15
16
17
18
# File 'lib/lakes/texas/fishing_report_parser.rb', line 12

def initialize(text)
  @raw_text = text
  @raw_date = nil
  @date = nil
  @report = nil
  parse
end

Instance Attribute Details

#dateObject (readonly)

Returns the value of attribute date.



9
10
11
# File 'lib/lakes/texas/fishing_report_parser.rb', line 9

def date
  @date
end

#raw_dateObject (readonly)

Returns the value of attribute raw_date.



8
9
10
# File 'lib/lakes/texas/fishing_report_parser.rb', line 8

def raw_date
  @raw_date
end

#raw_textObject (readonly)

Returns the value of attribute raw_text.



7
8
9
# File 'lib/lakes/texas/fishing_report_parser.rb', line 7

def raw_text
  @raw_text
end

#reportObject (readonly)

Returns the value of attribute report.



10
11
12
# File 'lib/lakes/texas/fishing_report_parser.rb', line 10

def report
  @report
end

Instance Method Details

#parseObject



20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/lakes/texas/fishing_report_parser.rb', line 20

def parse
  current_fishing_report_doc = Nokogiri::HTML(raw_text)
  current_fishing_report_dl = current_fishing_report_doc.at('div.row.report div.container dl')
  return if current_fishing_report_dl.nil?

  date_text = current_fishing_report_dl.at('dt span.title').try(:text)
  @raw_date = cleanup_data(date_text) unless date_text.nil?

  @date = Date.parse(@raw_date) rescue nil

  report_text = current_fishing_report_dl.xpath('dd').try(:text)
  @report = cleanup_data(report_text) unless report_text.nil?
end