Class: Lakes::Texas

Inherits:
Object show all
Defined in:
lib/lakes/texas.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeTexas



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

def initialize
  @lake_data = {}
end

Instance Attribute Details

#lake_dataObject (readonly)

Returns the value of attribute lake_data.



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

def lake_data
  @lake_data
end

Instance Method Details

#get_details(lake_name) ⇒ Object



33
34
35
36
37
38
39
40
# File 'lib/lakes/texas.rb', line 33

def get_details(lake_name)
  puts "getting details for #{lake_name}"
  list
  data = lake_data[lake_name]
  raise 'Lake not found' if data.nil?
  data[:name] = lake_name
  parse_lake_details(data)
end

#listObject



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/lakes/texas.rb', line 14

def list
  return @lake_data.keys unless @lake_data.empty?

  base_url = 'http://tpwd.texas.gov/fishboat/fish/recreational/lakes/'
  content = http_get("#{base_url}lakelist.phtml")
  html_doc = Nokogiri::HTML(content)
  
  # remove elements not needed to make parsing easier
  html_doc.search('div.announce, div.alert, div#bottomwrapper').each do |src|
    src.remove
  end

  html_doc.search('div#maincontent ul li a').each do |lake_html|
    lake_name = cleanup_data(lake_html.text)
    @lake_data[lake_name] = { details_uri: "#{base_url}#{lake_html[:href]}" }
  end
  @lake_data.keys
end