lakes 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (5) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -0
  3. data/lib/lakes/texas.rb +24 -29
  4. data/lib/lakes.rb +1 -1
  5. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e2f90d9155261969985aeb991728e30ff9adbbe3
4
- data.tar.gz: be510c54220703644f910f3983a0e196956050a3
3
+ metadata.gz: 2234be1dd9e85792994fd9943a08ecf2768128c2
4
+ data.tar.gz: 727102c0fa0e2f682ac22bd45bcde550a244f9e6
5
5
  SHA512:
6
- metadata.gz: 308594624b25d80c2dccae8301f31088297f53072cdbc75037d9d23279536e7520f7a84f5f1d46034dde4e86db5980aa2cdfd648b63e905b29abe465fc44c6da
7
- data.tar.gz: 6d62789d2a0f3cdefa2bfd6f6a5976e1a015dc3949bad710d4e2888d074b9fb1cb09cc64727767ff09c232f0934720d20ac92359c66316dab1c1d430986e1358
6
+ metadata.gz: c3182d5719093b93edfc3e44a05d831c689e263321be8dd639582a22dcc4026e316e636206c0543989012042d01eb41f62bb3b65447d443debc64aa46a52ab1e
7
+ data.tar.gz: 4ef88d976d9d2d8fec82ecb7bf3735158ad4fe84e45f53a4ff01da13dd586035a51f944c2b64c345b94aea582d49578580a9519ce565e90de1e7524973b6ac14
data/.gitignore CHANGED
@@ -7,3 +7,4 @@
7
7
  /pkg/
8
8
  /spec/reports/
9
9
  /tmp/
10
+ *.gem
data/lib/lakes/texas.rb CHANGED
@@ -15,8 +15,7 @@ module Lakes
15
15
  return @lake_data.keys unless @lake_data.empty?
16
16
 
17
17
  base_url = 'http://tpwd.texas.gov/fishboat/fish/recreational/lakes/'
18
- uri = URI("#{base_url}lakelist.phtml")
19
- content = Net::HTTP.get(uri)
18
+ content = http_get("#{base_url}lakelist.phtml")
20
19
  html_doc = Nokogiri::HTML(content)
21
20
 
22
21
  # remove elements not needed to make parsing easier
@@ -42,9 +41,7 @@ module Lakes
42
41
  protected
43
42
 
44
43
  def parse_lake_details(lake_data)
45
- uri = URI(lake_data[:details_uri] + '/')
46
- content = Net::HTTP.get(uri).encode('UTF-8', 'Windows-1252')
47
-
44
+ content = http_get(lake_data[:details_uri] + '/')
48
45
  html_doc = Nokogiri::HTML(content)
49
46
  main_div = html_doc.at('div#maincontent')
50
47
 
@@ -103,39 +100,27 @@ module Lakes
103
100
  end
104
101
 
105
102
  def parse_fishing_regulations(main_div, lake_data)
106
- data = main_div.xpath('//h6[contains(text(), "Fishing Regulations")]').first
107
- content = data.try(:next_element).try(:to_html)
108
- lake_data[:fishing_regulations] = content
103
+ process_simple_section(main_div, lake_data, 'Fishing Regulations', :fishing_regulations, true)
109
104
  end
110
105
 
111
106
  def parse_lake_maps(main_div, lake_data)
112
- data = main_div.xpath('//h6[contains(text(), "Lake Maps")]').first
113
- content = data.try(:next_element).try(:text)
114
- lake_data[:lake_maps] = content
107
+ process_simple_section(main_div, lake_data, 'Lake Maps', :lake_maps, false)
115
108
  end
116
109
 
117
110
  def parse_lake_characteristics(main_div, lake_data)
118
- data = main_div.xpath('//h6[contains(text(), "Lake Characteristics")]').first
119
- content = data.try(:next_element).try(:text)
120
- lake_data[:lake_characteristics] = content
111
+ process_simple_section(main_div, lake_data, 'Lake Characteristics', :lake_characteristics, false)
121
112
  end
122
113
 
123
114
  def parse_water_conditions(main_div, lake_data)
124
- data = main_div.xpath('//h6[contains(text(), "Water Conditions")]').first
125
- content = data.try(:next_element).try(:to_html)
126
- lake_data[:water_conditions] = content
115
+ process_simple_section(main_div, lake_data, 'Water Conditions', :water_conditions, true)
127
116
  end
128
117
 
129
118
  def parse_reservoir_controlling_authority(main_div, lake_data)
130
- data = main_div.xpath('//h6[contains(text(), "Reservoir Controlling Authority")]').first
131
- content = data.try(:next_element).try(:text)
132
- lake_data[:reservoir_controlling_authority] = content
119
+ process_simple_section(main_div, lake_data, 'Reservoir Controlling Authority', :reservoir_controlling_authority, false)
133
120
  end
134
121
 
135
122
  def parse_aquatic_vegetation(main_div, lake_data)
136
- data = main_div.xpath('//h6[contains(text(), "Aquatic Vegetation")]').first
137
- content = data.try(:next_element).try(:text)
138
- lake_data[:aquatic_vegetation] = content
123
+ process_simple_section(main_div, lake_data, 'Aquatic Vegetation', :aquatic_vegetation, false)
139
124
  end
140
125
 
141
126
  def parse_predominant_fish_species(main_div, lake_data)
@@ -163,8 +148,7 @@ module Lakes
163
148
  uri = link['href']
164
149
  lake_data[:stocking_history_uri] = convert_relative_href(uri, lake_data[:details_uri])
165
150
 
166
- uri = URI(lake_data[:stocking_history_uri])
167
- content = Net::HTTP.get(uri).encode('UTF-8', 'Windows-1252')
151
+ content = http_get(lake_data[:stocking_history_uri])
168
152
  stocking_history_doc = Nokogiri::HTML(content)
169
153
 
170
154
  stocking_history_table = stocking_history_doc.at('div#maincontent table')
@@ -184,8 +168,7 @@ module Lakes
184
168
  uri = link['href']
185
169
  lake_data[:current_fishing_report_uri] = convert_relative_href(uri, lake_data[:details_uri])
186
170
 
187
- uri = URI(lake_data[:current_fishing_report_uri])
188
- content = Net::HTTP.get(uri).encode('UTF-8', 'Windows-1252')
171
+ content = http_get(lake_data[:current_fishing_report_uri])
189
172
  current_fishing_report_doc = Nokogiri::HTML(content)
190
173
  current_fishing_report_dl = current_fishing_report_doc.at('div.row.report div.container dl')
191
174
 
@@ -206,8 +189,7 @@ module Lakes
206
189
  uri = link['href']
207
190
  lake_data[:fishing_records_uri] = convert_relative_href(uri, lake_data[:details_uri])
208
191
 
209
- uri = URI(lake_data[:fishing_records_uri])
210
- content = Net::HTTP.get(uri).encode('UTF-8', 'Windows-1252')
192
+ content = http_get(lake_data[:fishing_records_uri])
211
193
  lake_records_doc = Nokogiri::HTML(content)
212
194
  lake_records_main_div = lake_records_doc.at('div#maincontent')
213
195
 
@@ -286,5 +268,18 @@ module Lakes
286
268
  value = value.strip.gsub(nbsp, '')
287
269
  value.empty? ? nil : value
288
270
  end
271
+
272
+ def process_simple_section(main_div, lake_data, section_title, data_name, html)
273
+ data = main_div.xpath("//h6[contains(text(), \"#{section_title}\")]").first
274
+ element_type_function = html ? :to_html : :text
275
+ content = data.try(:next_element).try(element_type_function)
276
+ lake_data[data_name] = content
277
+ end
278
+
279
+ # texas lake pages are encoded in Windows-1252 :(
280
+ def http_get(url)
281
+ uri = URI(url)
282
+ Net::HTTP.get(uri).encode('UTF-8', 'Windows-1252')
283
+ end
289
284
  end
290
285
  end
data/lib/lakes.rb CHANGED
@@ -1,4 +1,4 @@
1
1
  require 'lakes/texas'
2
2
  module Lakes
3
- VERSION = '0.1.0'
3
+ VERSION = '0.1.1'
4
4
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lakes
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Shane Sherman
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-11-14 00:00:00.000000000 Z
11
+ date: 2016-11-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler