lakes 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2234be1dd9e85792994fd9943a08ecf2768128c2
4
- data.tar.gz: 727102c0fa0e2f682ac22bd45bcde550a244f9e6
3
+ metadata.gz: 4fd4734a4458713c26f87380650f9f997b69ee47
4
+ data.tar.gz: 98432482a89cac25e45637a1acd4a50d4d3fd5e3
5
5
  SHA512:
6
- metadata.gz: c3182d5719093b93edfc3e44a05d831c689e263321be8dd639582a22dcc4026e316e636206c0543989012042d01eb41f62bb3b65447d443debc64aa46a52ab1e
7
- data.tar.gz: 4ef88d976d9d2d8fec82ecb7bf3735158ad4fe84e45f53a4ff01da13dd586035a51f944c2b64c345b94aea582d49578580a9519ce565e90de1e7524973b6ac14
6
+ metadata.gz: 1e95cffa65e7e8778f7ae086dfc651d4b1f1dcd0e602b57fdad0a942745e0be6eff3e81a660020951184317811af5527d88ab477c1355df22f40c660576dadb2
7
+ data.tar.gz: ed6fb9047856f64ea9ab52fbda4ea31e6895132998f2e06ce4877d649136968fd2d5ac0e7431e00afd94dd206f909481d228dfc44127ebcff243ee171ecca2d6
data/lakes.gemspec CHANGED
@@ -16,10 +16,10 @@ Gem::Specification.new do |spec|
16
16
  spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
17
17
  spec.bindir = "exe"
18
18
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
19
- spec.require_paths = ["lib"]
19
+ spec.require_paths = ['lib']
20
20
 
21
21
  spec.add_development_dependency "bundler", "~> 1.11"
22
22
  spec.add_development_dependency "rake", "~> 10.0"
23
23
  spec.add_development_dependency "minitest", "~> 5.0"
24
- spec.add_development_dependency 'nokogiri', "~> 1.6"
24
+ spec.add_development_dependency 'nokogiri', "~> 1.7"
25
25
  end
@@ -0,0 +1,57 @@
1
+ class LakeCharacteristicsParser
2
+ attr_reader :raw_text, :location_desc
3
+ attr_reader :surface_area_raw_text, :surface_area_in_acres
4
+ attr_reader :max_depth_raw_text, :max_depth_in_feet
5
+ attr_reader :year_impounded_raw_text, :year_impounded
6
+
7
+ def initialize(text)
8
+ @raw_text = text
9
+ parse
10
+ end
11
+
12
+ def parse
13
+ @location_desc = @raw_text.match(/^location:(.*)(surface area)|(surface acres)|(maximum depth|impounded):/im).captures.first
14
+ @surface_area_raw_text = @raw_text.match(/surface (area|acres):(.*)/i).try(:captures).try(:[], 1)
15
+ @max_depth_raw_text = @raw_text.match(/maximum depth:(.*)/i).try(:captures).try(:first)
16
+ @year_impounded_raw_text = @raw_text.match(/impounded:(.*)/im).try(:captures).try(:first)
17
+
18
+ @location_desc = cleanup_raw_text(@location_desc)
19
+
20
+ @surface_area_in_acres = cleanup_raw_text(@surface_area_raw_text)
21
+ .try(:match, /^([0-9,]+)/)
22
+ .try(:captures)
23
+ .try(:first)
24
+ .try(:delete, ',')
25
+ .try(:to_i)
26
+
27
+ @max_depth_in_feet = cleanup_raw_text(@max_depth_raw_text)
28
+ .try(:match, /^([0-9,]+)/)
29
+ .try(:captures)
30
+ .try(:first)
31
+ .try(:delete, ',')
32
+ .try(:to_i)
33
+
34
+ # need to handle bad data like Lake Fryer which is:
35
+ # Maximum depth: Average 13 feet, maximum 25 feet
36
+ if @max_depth_in_feet.nil?
37
+ @max_depth_in_feet = cleanup_raw_text(@max_depth_raw_text)
38
+ .try(:match, /maximum ([0-9,]+) feet/i)
39
+ .try(:captures)
40
+ .try(:first)
41
+ .try(:delete, ',')
42
+ .try(:to_i)
43
+ end
44
+
45
+ @year_impounded = cleanup_raw_text(@year_impounded_raw_text)
46
+ .try(:match, /([0-9,]+)/)
47
+ .try(:captures)
48
+ .try(:first)
49
+ .try(:delete, ',')
50
+ .try(:to_i)
51
+
52
+ end
53
+
54
+ def cleanup_raw_text(raw_text)
55
+ raw_text.try(:gsub, /\s+/, ' ').try(:strip)
56
+ end
57
+ end
data/lib/lakes/texas.rb CHANGED
@@ -31,10 +31,11 @@ module Lakes
31
31
  end
32
32
 
33
33
  def get_details(lake_name)
34
+ puts "getting details for #{lake_name}"
34
35
  list
35
36
  data = lake_data[lake_name]
36
37
  raise 'Lake not found' if data.nil?
37
-
38
+ data[:name] = lake_name
38
39
  parse_lake_details(data)
39
40
  end
40
41
 
@@ -50,15 +51,15 @@ module Lakes
50
51
  parse_reservoir_controlling_authority(main_div, lake_data)
51
52
  parse_aquatic_vegetation(main_div, lake_data)
52
53
  parse_predominant_fish_species(main_div, lake_data)
53
- parse_lake_records(main_div, lake_data)
54
54
  parse_current_fishing_report(main_div, lake_data)
55
- parse_stocking_history(main_div, lake_data)
56
55
  parse_lake_surveys(main_div, lake_data)
57
56
  parse_lake_maps(main_div, lake_data)
58
57
  parse_fishing_regulations(main_div, lake_data)
59
58
  parse_angling_opportunities(main_div, lake_data)
60
59
  parse_fishing_structure(main_div, lake_data)
61
60
  parse_tips_and_tactics(main_div, lake_data)
61
+ parse_lake_records(main_div, lake_data)
62
+ parse_stocking_history(main_div, lake_data)
62
63
  lake_data
63
64
  end
64
65
 
@@ -108,7 +109,17 @@ module Lakes
108
109
  end
109
110
 
110
111
  def parse_lake_characteristics(main_div, lake_data)
111
- process_simple_section(main_div, lake_data, 'Lake Characteristics', :lake_characteristics, false)
112
+ data = main_div.xpath("//h6[contains(text(), 'Lake Characteristics')]").first
113
+ content = data.try(:next_element).try(:text).try(:strip)
114
+ lake_data[:raw_lake_characteristics] = content
115
+
116
+ parser = LakeCharacteristicsParser.new(content)
117
+
118
+ lake_data[:lake_characteristics] = {}
119
+ lake_data[:lake_characteristics][:location_desc] = parser.location_desc
120
+ lake_data[:lake_characteristics][:surface_area_in_acres] = parser.surface_area_in_acres
121
+ lake_data[:lake_characteristics][:max_depth_in_feet] = parser.max_depth_in_feet
122
+ lake_data[:lake_characteristics][:year_impounded] = parser.year_impounded
112
123
  end
113
124
 
114
125
  def parse_water_conditions(main_div, lake_data)
data/lib/lakes.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  require 'lakes/texas'
2
+ require 'lakes/texas/lake_characteristics_parser'
2
3
  module Lakes
3
- VERSION = '0.1.1'
4
+ VERSION = '0.1.2'.freeze
4
5
  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.1
4
+ version: 0.1.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: 2016-11-15 00:00:00.000000000 Z
11
+ date: 2017-01-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -58,14 +58,14 @@ dependencies:
58
58
  requirements:
59
59
  - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: '1.6'
61
+ version: '1.7'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
- version: '1.6'
68
+ version: '1.7'
69
69
  description: I wrote this gem to originally parse texas lake data
70
70
  email:
71
71
  - shane.sherman@gmail.com
@@ -85,6 +85,7 @@ files:
85
85
  - lakes.json
86
86
  - lib/lakes.rb
87
87
  - lib/lakes/texas.rb
88
+ - lib/lakes/texas/lake_characteristics_parser.rb
88
89
  - lib/try.rb
89
90
  homepage:
90
91
  licenses:
@@ -106,7 +107,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
106
107
  version: '0'
107
108
  requirements: []
108
109
  rubyforge_project:
109
- rubygems_version: 2.5.1
110
+ rubygems_version: 2.6.8
110
111
  signing_key:
111
112
  specification_version: 4
112
113
  summary: This gem parses lake details from various government websites