Last active
January 21, 2016 00:51
-
-
Save mando/c33cb129af8f2f57cf25 to your computer and use it in GitHub Desktop.
Decimal degrees to minute/seconds degrees
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class DecimalDegree | |
# logic from http://mathforum.org/sarah/hamilton/ham.degrees.html | |
attr_accessor :decimal | |
def initialize(decimal) | |
@decimal = decimal.to_f | |
end | |
def convert_to_min_sec | |
degrees = decimal.to_int | |
minutes = ((decimal - degrees) * 60).abs | |
seconds = ((minutes - minutes.to_int) * 60).abs.round(2) | |
puts "#{degrees} #{minutes.to_int}\' #{seconds}\"" | |
end | |
end | |
if __FILE__ == $0 | |
DecimalDegree.new(ARGV.first).convert_to_min_sec | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ ruby decimal_degree.rb -27.116667 | |
-27 7' 0" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment