Module: Lakes::Helper

Instance Method Summary collapse

Instance Method Details

#cleanup_data(value) ⇒ Object

texas lake websites use lots of non breaking spaces



11
12
13
14
15
# File 'lib/lakes/helper.rb', line 11

def cleanup_data(value)
  nbsp = 160.chr('UTF-8')
  value = value.strip.gsub(nbsp, '')
  value.empty? ? nil : value
end

#cleanup_raw_text(raw_text) ⇒ Object



17
18
19
# File 'lib/lakes/helper.rb', line 17

def cleanup_raw_text(raw_text)
  raw_text.try(:gsub, /\s+/, ' ').try(:strip)
end

#convert_relative_href(href, current_url) ⇒ Object

converts this: ../../../action/waterecords.php?WB_code=0001 into this: tpwd.texas.gov/fishboat/fish/action/waterecords.php?WB_code=0001 based on this: tpwd.texas.gov/fishboat/fish/recreational/lakes/abilene



27
28
29
30
31
32
33
# File 'lib/lakes/helper.rb', line 27

def convert_relative_href(href, current_url)
  relative_depth = href.split('..').count - 1
  url_parts = current_url.split('/')
  url_parts.slice!(-relative_depth, relative_depth)
  fixed_href = href.gsub('../', '')
  url_parts.join('/') + '/' + fixed_href
end

#http_get(url) ⇒ Object

texas lake pages are encoded in Windows-1252 :(



5
6
7
8
# File 'lib/lakes/helper.rb', line 5

def http_get(url)
  uri = URI(url)
  Net::HTTP.get(uri).encode('UTF-8', 'Windows-1252')
end