Sha256: 2ff0eb1022951402d1d433facf58e91e8ae814d4e32c53befe84713d4bd732d8

Contents?: true

Size: 1.5 KB

Versions: 1

Compression:

Stored size: 1.5 KB

Contents

module GeoCalc
  module PrettyPrint
    # Returns the latitude of this point; signed numeric degrees if no format, otherwise format & dp 
    # as per Geo.to_lat
    # 
    # - String [format]: Return value as 'd', 'dm', 'dms'
    # - Numeric [dp=0|2|4]: No of decimal places to display
    #
    # Returns {Numeric|String}: Numeric degrees if no format specified, otherwise deg/min/sec
    # 

    def to_lat format = :dms, dp = 0
      return lat if !format
      Geo.to_lat lat, format, dp
    end


    # Returns the longitude of this point; signed numeric degrees if no format, otherwise format & dp 
    # as per Geo.toLon()
    # 
    # @param   {String} [format]: Return value as 'd', 'dm', 'dms'
    # @param   {Number} [dp=0|2|4]: No of decimal places to display
    # @returns {Number|String} Numeric degrees if no format specified, otherwise deg/min/sec
    # 
    # @requires Geo

    def to_lon format, dp
      return lon if !format
      Geo.to_lon lon, format, dp
    end


    # Returns a string representation of this point; format and dp as per lat()/lon()
    # 
    # @param   {String} [format]: Return value as 'd', 'dm', 'dms'
    # @param   {Number} [dp=0|2|4]: No of decimal places to display

    # @returns {String} Comma-separated latitude/longitude
    # 

    def to_s format = :dms, dp = 0 
      format ||= :dms

      return '-,-' if !lat || !lon

      _lat = GeoUnits::Converter.to_lat lat, format, dp
      _lon = GeoUnits::Converter.to_lon lon, format, dp

      "#{_lat}, #{_lon}"
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
geo_calc-0.7.1 lib/geo_calc/pretty_print.rb