Class: Lakes::Texas::WaterDataParser
- Includes:
- Helper
- Defined in:
- lib/lakes/texas/water_data_parser.rb
Instance Attribute Summary collapse
-
#conservation_pool_elevation_in_ft_msl ⇒ Object
readonly
Returns the value of attribute conservation_pool_elevation_in_ft_msl.
-
#percentage_full ⇒ Object
readonly
Returns the value of attribute percentage_full.
-
#raw_text ⇒ Object
readonly
Returns the value of attribute raw_text.
Instance Method Summary collapse
-
#initialize(text) ⇒ WaterDataParser
constructor
A new instance of WaterDataParser.
- #parse ⇒ Object
Methods included from Helper
#cleanup_data, #cleanup_raw_text, #convert_relative_href, #http_get, #process_data_table
Constructor Details
#initialize(text) ⇒ WaterDataParser
Returns a new instance of WaterDataParser.
11 12 13 14 15 16 |
# File 'lib/lakes/texas/water_data_parser.rb', line 11 def initialize(text) @raw_text = text # File.write("test/data/water_data/Abilene.txt", @raw_text) # puts "WaterDataParser: raw_text: #{@raw_text}" parse end |
Instance Attribute Details
#conservation_pool_elevation_in_ft_msl ⇒ Object (readonly)
Returns the value of attribute conservation_pool_elevation_in_ft_msl.
8 9 10 |
# File 'lib/lakes/texas/water_data_parser.rb', line 8 def conservation_pool_elevation_in_ft_msl @conservation_pool_elevation_in_ft_msl end |
#percentage_full ⇒ Object (readonly)
Returns the value of attribute percentage_full.
9 10 11 |
# File 'lib/lakes/texas/water_data_parser.rb', line 9 def percentage_full @percentage_full end |
#raw_text ⇒ Object (readonly)
Returns the value of attribute raw_text.
7 8 9 |
# File 'lib/lakes/texas/water_data_parser.rb', line 7 def raw_text @raw_text end |
Instance Method Details
#parse ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/lakes/texas/water_data_parser.rb', line 18 def parse html_doc = Nokogiri::HTML(@raw_text) cons_pool_elevation_header_element = html_doc.xpath('//td[contains(text(), "Conservation pool elevation")]').first cons_pool_elevation_root = cons_pool_elevation_header_element.try(:next_element) @conservation_pool_elevation_in_ft_msl = cleanup_raw_text(cons_pool_elevation_root.try(:text)) .try(:match, /([0-9,\.]+)/) .try(:captures) .try(:first) .try(:gsub, ',', '') .try(:to_f) percentage_full_element = cleanup_raw_text(html_doc.css('div.page-title h2 small').try(:text)) @percentage_full = percentage_full_element .try(:match, /^([0-9]+\.?[0-9]+)/) .try(:captures) .try(:first) .try(:to_f) end |