Class: NjFishingReport::Scraper

Inherits:
Object
  • Object
show all
Defined in:
lib/nj_fishing_report/scraper.rb

Constant Summary collapse

BASE_PATH =
"http://www.fishingreportsnow.com/New_Jersey_Fishing_Reports_Pro.cfm/reg/7"

Class Method Summary collapse

Class Method Details

.scrape_fishing_locationObject



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/nj_fishing_report/scraper.rb', line 6

def self.scrape_fishing_location

  doc = Nokogiri::HTML(open(BASE_PATH))

  fishing_locations = []

  doc.css("td.reportstext a").each do |potential_location|
    if potential_location.attribute("href").value[0,30] == "New_Jersey_Fishing_Reports_Pro" && potential_location.text != "Last Week's Report"
      fishing_locations << potential_location
    end
  end

  fishing_locations.each do |location|
    fishing_location = location.text
     fishing_location = NjFishingReport::Fishing_Location.new(location.text)
    fishing_location.url = "http://www.fishingreportsnow.com/" + location.attribute("href").value
  end
end

.scrape_fishing_reportObject



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/nj_fishing_report/scraper.rb', line 26

def self.scrape_fishing_report

  NjFishingReport::Fishing_Location.all.each do |location|

    doc = Nokogiri::HTML(open(location.url))

    doc.css("td.reportstext").each do |scraping_only_if_fishing_report|
      if scraping_only_if_fishing_report.attribute("align").value == "left"

        instance_of_fishing_report = NjFishingReport::Fishing_Report.new(scraping_only_if_fishing_report.text.strip)

        instance_of_fishing_report.fishing_location = NjFishingReport::Fishing_Location.all.detect {|instance| instance.name == location.name}

        instance_of_fishing_location = NjFishingReport::Fishing_Location.all.detect {|instance| instance.name == location.name}

        instance_of_fishing_location.fishing_report = instance_of_fishing_report

      end
    end
  end
end