Class: Lakes::Texas::WaterConditionsParser
- Includes:
- Helper
- Defined in:
- lib/lakes/texas/water_conditions_parser.rb
Instance Attribute Summary collapse
-
#conservation_pool_elevation ⇒ Object
readonly
Returns the value of attribute conservation_pool_elevation.
-
#conservation_pool_elevation_in_ft_msl ⇒ Object
readonly
Returns the value of attribute conservation_pool_elevation_in_ft_msl.
-
#conservation_pool_elevation_raw_text ⇒ Object
readonly
Returns the value of attribute conservation_pool_elevation_raw_text.
-
#fluctuation ⇒ Object
readonly
Returns the value of attribute fluctuation.
-
#fluctuation_raw_text ⇒ Object
readonly
Returns the value of attribute fluctuation_raw_text.
-
#normal_clarity ⇒ Object
readonly
Returns the value of attribute normal_clarity.
-
#normal_clarity_raw_text ⇒ Object
readonly
Returns the value of attribute normal_clarity_raw_text.
-
#raw_text ⇒ Object
readonly
Returns the value of attribute raw_text.
-
#raw_text_without_whitespace ⇒ Object
readonly
Returns the value of attribute raw_text_without_whitespace.
-
#water_data_uri ⇒ Object
readonly
Returns the value of attribute water_data_uri.
Instance Method Summary collapse
-
#initialize(text) ⇒ WaterConditionsParser
constructor
A new instance of WaterConditionsParser.
-
#parse ⇒ Object
<a href=“waterdatafortexas.org/reservoirs/individual/belton”>Current Lake Level</a> Conservation Pool Elevation: 594 ft.
Methods included from Helper
#cleanup_data, #cleanup_raw_text, #convert_relative_href, #http_get
Constructor Details
#initialize(text) ⇒ WaterConditionsParser
Returns a new instance of WaterConditionsParser.
14 15 16 17 18 19 |
# File 'lib/lakes/texas/water_conditions_parser.rb', line 14 def initialize(text) return if text.nil? @raw_text = text @raw_text_without_whitespace = text.gsub(/[\t\r\n\f]+/, '').gsub(/\s\s/, ' ') parse end |
Instance Attribute Details
#conservation_pool_elevation ⇒ Object (readonly)
Returns the value of attribute conservation_pool_elevation.
9 10 11 |
# File 'lib/lakes/texas/water_conditions_parser.rb', line 9 def conservation_pool_elevation @conservation_pool_elevation end |
#conservation_pool_elevation_in_ft_msl ⇒ Object (readonly)
Returns the value of attribute conservation_pool_elevation_in_ft_msl.
10 11 12 |
# File 'lib/lakes/texas/water_conditions_parser.rb', line 10 def conservation_pool_elevation_in_ft_msl @conservation_pool_elevation_in_ft_msl end |
#conservation_pool_elevation_raw_text ⇒ Object (readonly)
Returns the value of attribute conservation_pool_elevation_raw_text.
9 10 11 |
# File 'lib/lakes/texas/water_conditions_parser.rb', line 9 def conservation_pool_elevation_raw_text @conservation_pool_elevation_raw_text end |
#fluctuation ⇒ Object (readonly)
Returns the value of attribute fluctuation.
11 12 13 |
# File 'lib/lakes/texas/water_conditions_parser.rb', line 11 def fluctuation @fluctuation end |
#fluctuation_raw_text ⇒ Object (readonly)
Returns the value of attribute fluctuation_raw_text.
11 12 13 |
# File 'lib/lakes/texas/water_conditions_parser.rb', line 11 def fluctuation_raw_text @fluctuation_raw_text end |
#normal_clarity ⇒ Object (readonly)
Returns the value of attribute normal_clarity.
12 13 14 |
# File 'lib/lakes/texas/water_conditions_parser.rb', line 12 def normal_clarity @normal_clarity end |
#normal_clarity_raw_text ⇒ Object (readonly)
Returns the value of attribute normal_clarity_raw_text.
12 13 14 |
# File 'lib/lakes/texas/water_conditions_parser.rb', line 12 def normal_clarity_raw_text @normal_clarity_raw_text end |
#raw_text ⇒ Object (readonly)
Returns the value of attribute raw_text.
7 8 9 |
# File 'lib/lakes/texas/water_conditions_parser.rb', line 7 def raw_text @raw_text end |
#raw_text_without_whitespace ⇒ Object (readonly)
Returns the value of attribute raw_text_without_whitespace.
7 8 9 |
# File 'lib/lakes/texas/water_conditions_parser.rb', line 7 def raw_text_without_whitespace @raw_text_without_whitespace end |
#water_data_uri ⇒ Object (readonly)
Returns the value of attribute water_data_uri.
8 9 10 |
# File 'lib/lakes/texas/water_conditions_parser.rb', line 8 def water_data_uri @water_data_uri end |
Instance Method Details
#parse ⇒ Object
<a href=“waterdatafortexas.org/reservoirs/individual/belton”>Current Lake Level</a> Conservation Pool Elevation: 594 ft. msl Fluctuation: 3-5 feet Normal Clarity: Moderate
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/lakes/texas/water_conditions_parser.rb', line 25 def parse html_doc = Nokogiri::HTML.fragment(@raw_text) html_doc_without_whitespace_chars = Nokogiri::HTML.fragment(raw_text_without_whitespace) water_data_link = html_doc_without_whitespace_chars.xpath('p/a[contains(text(), "Current Lake Level")]').first @water_data_uri = water_data_link.try(:[], 'href') if @water_data_uri && @water_data_uri.start_with?('http://') @water_data_uri.gsub!('http://', 'https://') end text_doc = html_doc.text text_doc_without_whitespace = html_doc_without_whitespace_chars.text # so many inconsistencies in the data @conservation_pool_elevation_raw_text = text_doc .match(/(Conservation Pool Elevation:(.*))|(Normal water level:(.*))/i) .try(:captures) .try(:compact) .try(:[], 1) @conservation_pool_elevation = cleanup_raw_text( @conservation_pool_elevation_raw_text ) @fluctuation_raw_text = text_doc.match(/Fluctuation: (.*)Normal Clarity:/im).try(:captures).try(:first) @fluctuation = cleanup_raw_text(@fluctuation_raw_text) @normal_clarity_raw_text = text_doc_without_whitespace.match(/Normal Clarity: (.*)/i).try(:captures).try(:first) @normal_clarity = cleanup_raw_text(@normal_clarity_raw_text) end |