Class: GeoPosition::Parser::Dms

Inherits:
Object
  • Object
show all
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

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

#degreesObject



14
15
16
# File 'lib/geo_position/parser/dms.rb', line 14

def degrees
  parsed[:degrees].to_i
end

#directionObject



26
27
28
# File 'lib/geo_position/parser/dms.rb', line 26

def direction
  parsed[:direction].upcase
end

#minutesObject



18
19
20
# File 'lib/geo_position/parser/dms.rb', line 18

def minutes
  parsed[:minutes].to_i
end

#secondsObject



22
23
24
# File 'lib/geo_position/parser/dms.rb', line 22

def seconds
  parsed[:seconds].to_f
end

#to_hashObject



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