Module: Utilities::Elevation
- Defined in:
- lib/utilities/elevation.rb
Defined Under Namespace
Classes: MethodFromLabel
Class Method Summary collapse
-
.convert_to_meters!(hsh, key) ⇒ Object
private
Converts the value in a hash from feet to meters.
- .elevation_regex_from_verbatim_label(text) ⇒ Object
Class Method Details
.convert_to_meters!(hsh, key) ⇒ Object (private)
Converts the value in a hash from feet to meters
55 56 57 |
# File 'lib/utilities/elevation.rb', line 55 def self.convert_to_meters!(hsh, key) hsh[key] = (hsh[key].to_f * 0.3048).round(2).to_s if hsh[key] end |
.elevation_regex_from_verbatim_label(text) ⇒ 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 |
# File 'lib/utilities/elevation.rb', line 14 def self.elevation_regex_from_verbatim_label(text) text = ' ' + text.downcase.squish + ' ' elevation = {} if (matchdata1 = text.match(/\D(\d*,?\d+)\s?[-–]\s?(\d*,?\d+) ?(m|ft|feet|meters)\.?\W/)) elevation[:verbatim_elevation] = matchdata1[0].strip elevation[:minimum_elevation] = matchdata1[1] elevation[:maximum_elevation] = matchdata1[2] elevation[:units] = matchdata1[3] elsif (matchdata1 = text.match(/\D(\d*,?\d+) ?(m|ft|feet|meters)\.?( ?(\+\/-|±) ?(\d+) ?(m|ft|feet|meters)?[. ]?)?\W/)) elevation[:verbatim_elevation] = matchdata1[0].strip elevation[:minimum_elevation] = matchdata1[1] elevation[:units] = matchdata1[2] elevation[:elevation_precision] = matchdata1[5] if matchdata1[5] end if elevation[:units] elevation[:units] = elevation[:units].gsub('feet', 'ft') .gsub('meters', 'm') .gsub('.', '') elevation[:verbatim_elevation] = elevation[:verbatim_elevation][0..-2] if elevation[:verbatim_elevation] =~ /[;,:).\/]$/ elevation[:minimum_elevation] = elevation[:minimum_elevation].gsub(',', '') if elevation[:minimum_elevation] elevation[:maximum_elevation] = elevation[:maximum_elevation].gsub(',', '') if elevation[:maximum_elevation] if elevation[:units].to_s == 'ft' convert_to_meters!(elevation, :minimum_elevation) convert_to_meters!(elevation, :maximum_elevation) convert_to_meters!(elevation, :elevation_precision) elevation[:units] = 'm' end return elevation else return {} end end |