Class: Lakes::Texas::LakeCharacteristicsParser
- Defined in:
- lib/lakes/texas/lake_characteristics_parser.rb
Instance Attribute Summary collapse
-
#location_desc ⇒ Object
readonly
Returns the value of attribute location_desc.
-
#max_depth_in_feet ⇒ Object
readonly
Returns the value of attribute max_depth_in_feet.
-
#max_depth_raw_text ⇒ Object
readonly
Returns the value of attribute max_depth_raw_text.
-
#raw_text ⇒ Object
readonly
Returns the value of attribute raw_text.
-
#surface_area_in_acres ⇒ Object
readonly
Returns the value of attribute surface_area_in_acres.
-
#surface_area_raw_text ⇒ Object
readonly
Returns the value of attribute surface_area_raw_text.
-
#year_impounded ⇒ Object
readonly
Returns the value of attribute year_impounded.
-
#year_impounded_raw_text ⇒ Object
readonly
Returns the value of attribute year_impounded_raw_text.
Instance Method Summary collapse
- #cleanup_raw_text(raw_text) ⇒ Object
-
#initialize(text) ⇒ LakeCharacteristicsParser
constructor
A new instance of LakeCharacteristicsParser.
- #parse ⇒ Object
Constructor Details
#initialize(text) ⇒ LakeCharacteristicsParser
Returns a new instance of LakeCharacteristicsParser.
9 10 11 12 |
# File 'lib/lakes/texas/lake_characteristics_parser.rb', line 9 def initialize(text) @raw_text = text parse end |
Instance Attribute Details
#location_desc ⇒ Object (readonly)
Returns the value of attribute location_desc.
4 5 6 |
# File 'lib/lakes/texas/lake_characteristics_parser.rb', line 4 def location_desc @location_desc end |
#max_depth_in_feet ⇒ Object (readonly)
Returns the value of attribute max_depth_in_feet.
6 7 8 |
# File 'lib/lakes/texas/lake_characteristics_parser.rb', line 6 def max_depth_in_feet @max_depth_in_feet end |
#max_depth_raw_text ⇒ Object (readonly)
Returns the value of attribute max_depth_raw_text.
6 7 8 |
# File 'lib/lakes/texas/lake_characteristics_parser.rb', line 6 def max_depth_raw_text @max_depth_raw_text end |
#raw_text ⇒ Object (readonly)
Returns the value of attribute raw_text.
4 5 6 |
# File 'lib/lakes/texas/lake_characteristics_parser.rb', line 4 def raw_text @raw_text end |
#surface_area_in_acres ⇒ Object (readonly)
Returns the value of attribute surface_area_in_acres.
5 6 7 |
# File 'lib/lakes/texas/lake_characteristics_parser.rb', line 5 def surface_area_in_acres @surface_area_in_acres end |
#surface_area_raw_text ⇒ Object (readonly)
Returns the value of attribute surface_area_raw_text.
5 6 7 |
# File 'lib/lakes/texas/lake_characteristics_parser.rb', line 5 def surface_area_raw_text @surface_area_raw_text end |
#year_impounded ⇒ Object (readonly)
Returns the value of attribute year_impounded.
7 8 9 |
# File 'lib/lakes/texas/lake_characteristics_parser.rb', line 7 def year_impounded @year_impounded end |
#year_impounded_raw_text ⇒ Object (readonly)
Returns the value of attribute year_impounded_raw_text.
7 8 9 |
# File 'lib/lakes/texas/lake_characteristics_parser.rb', line 7 def year_impounded_raw_text @year_impounded_raw_text end |
Instance Method Details
#cleanup_raw_text(raw_text) ⇒ Object
56 57 58 |
# File 'lib/lakes/texas/lake_characteristics_parser.rb', line 56 def cleanup_raw_text(raw_text) raw_text.try(:gsub, /\s+/, ' ').try(:strip) end |
#parse ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 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/lake_characteristics_parser.rb', line 14 def parse @location_desc = @raw_text.match(/^location:(.*)(surface area)|(surface acres)|(maximum depth|impounded):/im).captures.first @surface_area_raw_text = @raw_text.match(/surface (area|acres):(.*)/i).try(:captures).try(:[], 1) @max_depth_raw_text = @raw_text.match(/maximum depth:(.*)/i).try(:captures).try(:first) @year_impounded_raw_text = @raw_text.match(/impounded:(.*)/im).try(:captures).try(:first) @location_desc = cleanup_raw_text(@location_desc) @surface_area_in_acres = cleanup_raw_text(@surface_area_raw_text) .try(:match, /^([0-9,]+)/) .try(:captures) .try(:first) .try(:delete, ',') .try(:to_i) @max_depth_in_feet = cleanup_raw_text(@max_depth_raw_text) .try(:match, /^([0-9,]+)/) .try(:captures) .try(:first) .try(:delete, ',') .try(:to_i) # need to handle bad data like Lake Fryer which is: # Maximum depth: Average 13 feet, maximum 25 feet if @max_depth_in_feet.nil? @max_depth_in_feet = cleanup_raw_text(@max_depth_raw_text) .try(:match, /maximum ([0-9,]+) feet/i) .try(:captures) .try(:first) .try(:delete, ',') .try(:to_i) end @year_impounded = cleanup_raw_text(@year_impounded_raw_text) .try(:match, /([0-9,]+)/) .try(:captures) .try(:first) .try(:delete, ',') .try(:to_i) end |