Class: GeoPosition::Conversion::Longitude

Inherits:
Object
  • Object
show all
Defined in:
lib/geo_position/conversion/longitude.rb

Constant Summary collapse

BOUNDS =
(-180.0..180.0)

Instance Method Summary collapse

Constructor Details

#initialize(longitude) ⇒ Longitude

Returns a new instance of Longitude.



6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/geo_position/conversion/longitude.rb', line 6

def initialize(longitude)
  raise GeoPosition::Error::InvalidFloatError.new("Arguments could not be coerced to a float") unless valid_float?(longitude)
  raise GeoPosition::Error::InvalidLongitudeError.new("Latitde must be between -180 and 180 degrees: %s provided" % [longitude]) unless within_bounds?(longitude)

  @longitude = longitude.to_f

  @degrees = 0
  @minutes = 0
  @seconds = 0

  convert!
end

Instance Method Details

#degreesObject



19
20
21
# File 'lib/geo_position/conversion/longitude.rb', line 19

def degrees
  @degrees
end

#directionObject



31
32
33
# File 'lib/geo_position/conversion/longitude.rb', line 31

def direction
  determine_direction
end

#minutesObject



23
24
25
# File 'lib/geo_position/conversion/longitude.rb', line 23

def minutes
  @minutes
end

#secondsObject



27
28
29
# File 'lib/geo_position/conversion/longitude.rb', line 27

def seconds
  @seconds
end

#to_sObject



35
36
37
# File 'lib/geo_position/conversion/longitude.rb', line 35

def to_s
  "%s deg %s' %s\" %s" % [self.degrees, self.minutes, self.seconds, self.direction]
end