Class: GeoPosition::Conversion::Dms
- Inherits:
-
Object
- Object
- GeoPosition::Conversion::Dms
- Defined in:
- lib/geo_position/conversion/dms.rb
Overview
This is the main class that will perform the conversion from Degrees, Minutes, and Seconds
Constant Summary collapse
- ALLOWED_SECONDS =
(0.0..60.0)
- ALLOWED_DEGREES =
(0.0..180.0)
- ALLOWED_DIRECTIONS =
%w( N n E e S s W w )
- MINUTES_CONVERSION =
60
- SECONDS_CONVERSION =
3600
Instance Method Summary collapse
-
#degrees ⇒ Float
Returns the coerced degrees.
-
#direction ⇒ String
Returns the uppercased direction.
-
#initialize(degrees, minutes, seconds, direction) ⇒ void
constructor
Creates a new instance of the DMS conversion object.
-
#minutes ⇒ Float
Returns the coerced minutes.
-
#seconds ⇒ Float
Returns the coerced seconds.
-
#to_f ⇒ Float
Returns the converted DMS to a float for use with latitude/longitude.
-
#to_s ⇒ String
Returns the formatted string.
Constructor Details
#initialize(degrees, minutes, seconds, direction) ⇒ void
Creates a new instance of the DMS conversion object
30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/geo_position/conversion/dms.rb', line 30 def initialize(degrees, minutes, seconds, direction) raise GeoPosition::Error::InvalidDirectionError.new("Please provided a direction of N, S, E, or W") unless valid_direction?(direction) raise GeoPosition::Error::InvalidFloatError.new("Arguments could not be coerced to a float") unless valid_floats?([degrees, minutes, seconds]) raise GeoPosition::Error::InvalidDegreesError.new("Degrees must be between 0 and 180. %s was provided" % [degrees]) unless valid_degrees?(degrees) raise GeoPosition::Error::InvalidMinutesError.new("Minutes must be between 0 and 60. %s was provided" % [minutes]) unless valid_minutes?(minutes) raise GeoPosition::Error::InvalidSecondsError.new("Seconds must be between 0 and 60. %s was provided" % [seconds]) unless valid_seconds?(seconds) @degrees = degrees @minutes = minutes @seconds = seconds @direction = direction end |
Instance Method Details
#degrees ⇒ Float
Returns the coerced degrees
47 48 49 |
# File 'lib/geo_position/conversion/dms.rb', line 47 def degrees @degrees.to_f.abs end |
#direction ⇒ String
Returns the uppercased direction
68 69 70 |
# File 'lib/geo_position/conversion/dms.rb', line 68 def direction @direction.to_s[0,1].upcase end |
#minutes ⇒ Float
Returns the coerced minutes
54 55 56 |
# File 'lib/geo_position/conversion/dms.rb', line 54 def minutes @minutes.to_f end |
#seconds ⇒ Float
Returns the coerced seconds
61 62 63 |
# File 'lib/geo_position/conversion/dms.rb', line 61 def seconds @seconds.to_f end |
#to_f ⇒ Float
Returns the converted DMS to a float for use with latitude/longitude
82 83 84 |
# File 'lib/geo_position/conversion/dms.rb', line 82 def to_f convert! end |
#to_s ⇒ String
Returns the formatted string
75 76 77 |
# File 'lib/geo_position/conversion/dms.rb', line 75 def to_s "%s deg %s' %s\" %s" % [self.degrees.to_i, self.minutes.to_i, self.seconds, self.direction] end |