lakes 0.3.1 → 0.4.0

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: b37a1e19a3fa73eb9d98aec3c498c7e6bd6246b9
4
- data.tar.gz: b54c92c15b0cea9b3763c10ab596073da9b7c6b5
3
+ metadata.gz: 30258a90e0c078f8458d0e9b5a4d684feacffee4
4
+ data.tar.gz: cadf28eca8c3a73171d478ffaa78f4ca5a10b2db
5
5
  SHA512:
6
- metadata.gz: cf721b20906467b1e1a3c1da47e9f112a3262953d5031b1712203d499e461f409eb1709fcc95f0f4d8d4575b7e4890b9b6cc38bd2f0cf21dd8dc7e96740e85e9
7
- data.tar.gz: d1091d98b424c34a74b3e5a2af7140fadb010f70e4648b212491a1a0a762bde4d917b3710d58364384fa1f61ad123d918f706ff12a7159927838dd765cb75ea4
6
+ metadata.gz: 1eadff3e5c00966942b00fa265f2414d4079bdf0b71b3032ac535cd707380b739a94311e98c479805fbf5810c314f957eef410ef428851f05172c01240096222
7
+ data.tar.gz: 848ec09caf3c99270c8daa156d35795f2b2931600a6a9261d21c7535062a165e8b5f3ab92fdc475f1b9344416ddc13c56fec18b36130c5de90d221b739f1679b
data/lib/lakes/helper.rb CHANGED
@@ -15,7 +15,8 @@ module Lakes
15
15
  end
16
16
 
17
17
  def cleanup_raw_text(raw_text)
18
- raw_text.try(:gsub, /\s+/, ' ').try(:strip)
18
+ v = raw_text.try(:gsub, /\s+/, ' ').try(:strip)
19
+ v == "" ? nil : v
19
20
  end
20
21
 
21
22
  # converts this:
@@ -5,6 +5,16 @@ module Lakes
5
5
  include Lakes::Helper
6
6
  URL = 'https://tpwd.texas.gov/spdest/visitorcenters/tffc/sharelunker/archives/lunkersearch_adv.phtml'
7
7
 
8
+ WEEKDAYS = {
9
+ 'mon' => 'Monday',
10
+ 'tue' => 'Tuesday',
11
+ 'wed' => 'Wednesday',
12
+ 'thu' => 'Thursday',
13
+ 'fri' => 'Friday',
14
+ 'sat' => 'Saturday',
15
+ 'sun' => 'Sunday'
16
+ }
17
+
8
18
  def initialize
9
19
  @lunker_data = []
10
20
  end
@@ -17,31 +27,58 @@ module Lakes
17
27
  results = []
18
28
  html_doc.search('div#contentwide table tr').each_with_index do |row, index|
19
29
  next if index == 0
20
- data = row.search('th, td').to_a
30
+ data = row.search('th, td')
31
+
32
+ girth = cleanup_raw_text(data[6].text)
33
+ girth = girth.nil? ? nil : girth.to_f
34
+
35
+ length = cleanup_raw_text(data[5].text)
36
+ length = length.nil? ? nil : length.to_f
37
+
38
+ status = cleanup_raw_text(data[15].text)
39
+ died = status.try(:downcase)
40
+ died = if !died.nil?
41
+ died.match('died').try(:length) == 1
42
+ end
21
43
 
22
44
  results << {
23
45
  id: data[0].text.to_i,
24
- details_uri: data[0].search('a')[0][:href],
46
+ details_uri: convert_relative_href("../" + data[0].search('a')[0][:href], URL),
25
47
  date_caught: Date.strptime(cleanup_raw_text(data[1].text), '%m/%d/%Y'),
26
48
  angler: cleanup_raw_text(data[2].text),
27
49
  angler_location: cleanup_raw_text(data[3].text),
28
50
  weight: cleanup_raw_text(data[4].text).to_f,
29
- length: cleanup_raw_text(data[5].text).to_f,
30
- girth: cleanup_raw_text(data[6].text).to_f,
51
+ length: length,
52
+ girth: girth,
31
53
  type: cleanup_raw_text(data[7].text),
32
54
  lake: cleanup_raw_text(data[8].text),
33
55
  record: cleanup_raw_text(data[9].text),
34
56
  caught_on: cleanup_raw_text(data[10].text),
35
- day_of_week: cleanup_raw_text(data[11].text),
57
+ day_of_week: WEEKDAYS[cleanup_raw_text(data[11].text).try(:downcase)],
36
58
  moon_phase: cleanup_raw_text(data[12].text),
37
- spawned: cleanup_raw_text(data[13].text),
38
- returned_to_lake: cleanup_raw_text(data[14].text),
39
- status: cleanup_raw_text(data[15].text)
59
+ spawned: convert_YN_boolean(cleanup_raw_text(data[13].text)),
60
+ returned_to_lake: convert_YN_boolean(cleanup_raw_text(data[14].text)),
61
+ status: cleanup_raw_text(data[15].text),
62
+ died: died
40
63
  }
41
64
  end
42
65
  @lunker_data = results
43
66
  return @lunker_data
44
67
  end
68
+
69
+ private
70
+ def convert_YN_boolean(value)
71
+ v = value.try(:downcase)
72
+ v = if v == 'Y'
73
+ true
74
+ elsif v == 'N'
75
+ false
76
+ else
77
+ nil
78
+ end
79
+ v
80
+ end
81
+
45
82
  end
46
83
  end
47
84
  end
data/lib/lakes.rb CHANGED
@@ -5,5 +5,5 @@ require 'lakes/texas/water_data_parser'
5
5
  require 'lakes/texas/fishing_report_parser'
6
6
  require 'lakes/texas/share_lunker'
7
7
  module Lakes
8
- VERSION = '0.3.1'.freeze
8
+ VERSION = '0.4.0'.freeze
9
9
  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.3.1
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Shane Sherman
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-04-20 00:00:00.000000000 Z
11
+ date: 2018-04-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler