Class: String
- Inherits:
-
Object
- Object
- String
- Defined in:
- lib/itudes.rb
Instance Method Summary collapse
-
#to_itude(strict = false) ⇒ Float
The multitude or ‘nil` if the convertion was not possible.
Instance Method Details
#to_itude(strict = false) ⇒ Float
Returns the multitude or ‘nil` if the convertion was not possible.
17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/itudes.rb', line 17 def to_itude strict = false case self when /^(?<val>[-+]?[0-9]*\.?[0-9]+([eE][-+]?[0-9]+)?)$/ # -53.133333 $~[:val].to_f when /(?<deg>\d+)[°\s]*(?<min>\d*)['’′\s]*(?<sec>\d*)["”″\s]*(?<ss>[NESWnesw]?)$/ # 53°11′18″N, 000°08′00″E f = $~[:deg].to_f + $~[:min].to_f / 60.0 + $~[:sec].to_f / 3600.0 ($~[:ss].to_s.downcase =~ /[sw]/).nil? ? f : -f else strict ? raise(TypeError.new "no implicit conversion of string “#{self}” to [Lat,Long]itude") : nil end end |