lakes 0.4.1 → 0.4.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/lakes.gemspec +1 -1
- data/lib/lakes.rb +1 -0
- data/lib/lakes/helper.rb +22 -0
- data/lib/lakes/texas.rb +2 -56
- data/lib/lakes/texas/lake_records_parser.rb +53 -0
- data/lib/version.rb +1 -1
- metadata +6 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: bb5405a6f87376435d2c48c39cf5b7eba4a8dcfa
|
4
|
+
data.tar.gz: 359f1231edc11c4beaf58331dbfa0ecdc86b7d57
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: '0390ee61eba90d6ad65454f6ddec96f74b5c0a0c33de32e0adfadca583ea69937d5dbb0de78316458b42406eebb45fc5b12e560411900876a69ff2ea7f8c75e9'
|
7
|
+
data.tar.gz: 9831a247e4c11c9b952d1776c9b835b2d470e5e29a1441febb9723e4c60defaeccca452f0d45676dac8be9e309b473d055590904c293a7984255c6813fd5cd41
|
data/lakes.gemspec
CHANGED
@@ -22,5 +22,5 @@ Gem::Specification.new do |spec|
|
|
22
22
|
spec.add_development_dependency "rake", "~> 12.3"
|
23
23
|
spec.add_development_dependency "minitest", "~> 5.11"
|
24
24
|
spec.add_development_dependency "mocha", "~> 1.2"
|
25
|
-
spec.add_dependency 'nokogiri', "~> 1.
|
25
|
+
spec.add_dependency 'nokogiri', "~> 1.10"
|
26
26
|
end
|
data/lib/lakes.rb
CHANGED
data/lib/lakes/helper.rb
CHANGED
@@ -19,6 +19,28 @@ module Lakes
|
|
19
19
|
v == "" ? nil : v
|
20
20
|
end
|
21
21
|
|
22
|
+
# converts a html table with headers and rows into
|
23
|
+
# an array of hashes with header => value
|
24
|
+
def process_data_table(headers, rows)
|
25
|
+
data = []
|
26
|
+
header_count = headers.length
|
27
|
+
row_count = rows.count / header_count
|
28
|
+
|
29
|
+
row_data_index = 0
|
30
|
+
row_count.times do |row_index|
|
31
|
+
|
32
|
+
entry = {}
|
33
|
+
header_count.times do |header_index|
|
34
|
+
header = cleanup_data(headers[header_index])
|
35
|
+
table_data = cleanup_data(rows[row_data_index])
|
36
|
+
row_data_index += 1
|
37
|
+
entry[header] = table_data
|
38
|
+
end
|
39
|
+
data << entry
|
40
|
+
end
|
41
|
+
data
|
42
|
+
end
|
43
|
+
|
22
44
|
# converts this:
|
23
45
|
# ../../../action/waterecords.php?WB_code=0001
|
24
46
|
# into this:
|
data/lib/lakes/texas.rb
CHANGED
@@ -234,62 +234,8 @@ module Lakes
|
|
234
234
|
lake_data[:fishing_records_uri] = convert_relative_href(uri, lake_data[:details_uri])
|
235
235
|
|
236
236
|
content = http_get(lake_data[:fishing_records_uri])
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
# H2's are record types like:
|
241
|
-
# - weight records
|
242
|
-
# - catch and release records (by length)
|
243
|
-
|
244
|
-
element = lake_records_main_div.children.first
|
245
|
-
current_record_type = nil # Weight or Length
|
246
|
-
current_age_group = nil # all ages, youth, etc
|
247
|
-
fishing_records_data = {}
|
248
|
-
while element = element.next_element
|
249
|
-
case element.name
|
250
|
-
when 'h2'
|
251
|
-
current_record_type = cleanup_data(element.text)
|
252
|
-
fishing_records_data[current_record_type] = {}
|
253
|
-
when 'h3'
|
254
|
-
current_age_group = cleanup_data(element.text)
|
255
|
-
fishing_records_data[current_record_type][current_age_group] = {}
|
256
|
-
when 'table'
|
257
|
-
fishing_method = cleanup_data(element.xpath('caption/big').text)
|
258
|
-
|
259
|
-
if fishing_records_data[current_record_type][current_age_group][fishing_method].nil?
|
260
|
-
fishing_records_data[current_record_type][current_age_group][fishing_method] = []
|
261
|
-
end
|
262
|
-
|
263
|
-
headers = element.xpath('tr/th').map{ |r| r.text }
|
264
|
-
rows = element.xpath('tr/td').map{ |r| r.text }
|
265
|
-
|
266
|
-
table_data = process_data_table(headers, rows)
|
267
|
-
fishing_records_data[current_record_type][current_age_group][fishing_method] = table_data
|
268
|
-
end
|
269
|
-
end
|
270
|
-
lake_data[:fishing_records] = fishing_records_data
|
271
|
-
end
|
272
|
-
|
273
|
-
# converts a html table with headers and rows into
|
274
|
-
# an array of hashes with header => value
|
275
|
-
def process_data_table(headers, rows)
|
276
|
-
data = []
|
277
|
-
header_count = headers.length
|
278
|
-
row_count = rows.count / header_count
|
279
|
-
|
280
|
-
row_data_index = 0
|
281
|
-
row_count.times do |row_index|
|
282
|
-
|
283
|
-
entry = {}
|
284
|
-
header_count.times do |header_index|
|
285
|
-
header = cleanup_data(headers[header_index])
|
286
|
-
table_data = cleanup_data(rows[row_data_index])
|
287
|
-
row_data_index += 1
|
288
|
-
entry[header] = table_data
|
289
|
-
end
|
290
|
-
data << entry
|
291
|
-
end
|
292
|
-
data
|
237
|
+
parser = LakeRecordsParser.new(content)
|
238
|
+
lake_data[:fishing_records] = parser.records
|
293
239
|
end
|
294
240
|
|
295
241
|
def process_simple_section(main_div, lake_data, section_title, data_name, html)
|
@@ -0,0 +1,53 @@
|
|
1
|
+
require 'nokogiri'
|
2
|
+
module Lakes
|
3
|
+
class Texas
|
4
|
+
class LakeRecordsParser
|
5
|
+
include Lakes::Helper
|
6
|
+
|
7
|
+
attr_reader :raw_text
|
8
|
+
attr_reader :records
|
9
|
+
|
10
|
+
def initialize(text)
|
11
|
+
@raw_text = text
|
12
|
+
@records = {}
|
13
|
+
parse
|
14
|
+
end
|
15
|
+
|
16
|
+
def parse
|
17
|
+
lake_records_doc = Nokogiri::HTML(@raw_text)
|
18
|
+
lake_records_main_div = lake_records_doc.at('div#maincontent')
|
19
|
+
|
20
|
+
# H2's are record types like:
|
21
|
+
# - weight records
|
22
|
+
# - catch and release records (by length)
|
23
|
+
|
24
|
+
element = lake_records_main_div.children.first
|
25
|
+
current_record_type = nil # Weight or Length
|
26
|
+
current_age_group = nil # all ages, youth, etc
|
27
|
+
while element = element.next_element
|
28
|
+
case element.name
|
29
|
+
when 'h2'
|
30
|
+
current_record_type = cleanup_data(element.text)
|
31
|
+
@records[current_record_type] = {}
|
32
|
+
when 'h3'
|
33
|
+
current_age_group = cleanup_data(element.text)
|
34
|
+
@records[current_record_type][current_age_group] = {}
|
35
|
+
when 'table'
|
36
|
+
fishing_method = cleanup_data(element.xpath('caption/big').text)
|
37
|
+
|
38
|
+
if @records[current_record_type][current_age_group][fishing_method].nil?
|
39
|
+
@records[current_record_type][current_age_group][fishing_method] = []
|
40
|
+
end
|
41
|
+
|
42
|
+
headers = element.xpath('tr/th').map{ |r| r.text }
|
43
|
+
rows = element.xpath('tr/td').map{ |r| r.text }
|
44
|
+
|
45
|
+
table_data = process_data_table(headers, rows)
|
46
|
+
@records[current_record_type][current_age_group][fishing_method] = table_data
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
data/lib/version.rb
CHANGED
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.4.
|
4
|
+
version: 0.4.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Shane Sherman
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2019-04-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -72,14 +72,14 @@ dependencies:
|
|
72
72
|
requirements:
|
73
73
|
- - "~>"
|
74
74
|
- !ruby/object:Gem::Version
|
75
|
-
version: '1.
|
75
|
+
version: '1.10'
|
76
76
|
type: :runtime
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
80
|
- - "~>"
|
81
81
|
- !ruby/object:Gem::Version
|
82
|
-
version: '1.
|
82
|
+
version: '1.10'
|
83
83
|
description: I wrote this gem to originally parse texas lake data
|
84
84
|
email:
|
85
85
|
- shane.sherman@gmail.com
|
@@ -102,6 +102,7 @@ files:
|
|
102
102
|
- lib/lakes/texas.rb
|
103
103
|
- lib/lakes/texas/fishing_report_parser.rb
|
104
104
|
- lib/lakes/texas/lake_characteristics_parser.rb
|
105
|
+
- lib/lakes/texas/lake_records_parser.rb
|
105
106
|
- lib/lakes/texas/share_lunker.rb
|
106
107
|
- lib/lakes/texas/water_conditions_parser.rb
|
107
108
|
- lib/lakes/texas/water_data_parser.rb
|
@@ -127,7 +128,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
127
128
|
version: '0'
|
128
129
|
requirements: []
|
129
130
|
rubyforge_project:
|
130
|
-
rubygems_version: 2.
|
131
|
+
rubygems_version: 2.6.12
|
131
132
|
signing_key:
|
132
133
|
specification_version: 4
|
133
134
|
summary: This gem parses lake details from various government websites
|