Class: GeoPosition::Parser::Dms
- Inherits:
-
Object
- Object
- GeoPosition::Parser::Dms
- Defined in:
- lib/geo_position/parser/dms.rb
Constant Summary collapse
- FORMAT_REGEX =
Regexp.new(/^(?<degrees>[\d]+)\s{1}[^\d]*(?<minutes>[\d]+)\s{1}(?<seconds>[\d]+(\.?[\d]+))\s{1}(?<direction>[nNsSeEwW]{1})/)
Instance Method Summary collapse
- #degrees ⇒ Object
- #direction ⇒ Object
-
#initialize(dms_string) ⇒ Dms
constructor
A new instance of Dms.
- #minutes ⇒ Object
- #seconds ⇒ Object
- #to_hash ⇒ Object
Constructor Details
#initialize(dms_string) ⇒ Dms
Returns a new instance of Dms.
6 7 8 9 10 11 12 |
# File 'lib/geo_position/parser/dms.rb', line 6 def initialize(dms_string) sanitize_string!(dms_string) raise GeoPosition::Error::InvalidDmsStringError.new('String could not be parsed') unless valid_string?(dms_string) @dms_string = dms_string.to_s end |
Instance Method Details
#degrees ⇒ Object
14 15 16 |
# File 'lib/geo_position/parser/dms.rb', line 14 def degrees parsed[:degrees].to_i end |
#direction ⇒ Object
26 27 28 |
# File 'lib/geo_position/parser/dms.rb', line 26 def direction parsed[:direction].upcase end |
#minutes ⇒ Object
18 19 20 |
# File 'lib/geo_position/parser/dms.rb', line 18 def minutes parsed[:minutes].to_i end |
#seconds ⇒ Object
22 23 24 |
# File 'lib/geo_position/parser/dms.rb', line 22 def seconds parsed[:seconds].to_f end |
#to_hash ⇒ Object
30 31 32 33 |
# File 'lib/geo_position/parser/dms.rb', line 30 def to_hash keys = [:degrees, :minutes, :seconds, :direction] keys.inject({}) { |hsh, key| hsh[key] = self.send(key); hsh } end |