Class: Resolv::LOC::Coord
Do not use. This class is for internal use only.
| Relationships & Source Files | |
| Inherits: | Object |
| Defined in: | lib/resolv.rb |
Overview
A Coord
Constant Summary
-
Bias =
# File 'lib/resolv.rb', line 3340
Biasfor the equator/prime meridian, in thousandths of a second of arc.1 << 31
-
Regex =
# File 'lib/resolv.rb', line 3337
Regular expression
::Resolv::LOCCoord must match./\A0*(\d{1,3})\s([0-5]?\d)\s([0-5]?\d(?:\.\d+)?)\s([NESW])\z/
Class Method Summary
-
.create(arg)
Creates a new
Coordfromargwhich may be: -
.new(coordinates, orientation) ⇒ Coord
constructor
Internal use; use self.create.
Instance Attribute Summary
-
#coordinates
readonly
The raw coordinates.
-
#orientation
readonly
The orientation of the hemisphere as 'lat' or 'lon'.
Instance Method Summary
Constructor Details
.new(coordinates, orientation) ⇒ Coord
Internal use; use self.create.
# File 'lib/resolv.rb', line 3372
def initialize(coordinates,orientation) unless coordinates.kind_of?(String) and coordinates.bytesize == 4 raise ArgumentError.new("Coord must be a 32bit unsigned integer in hex format: #{coordinates.inspect}") end unless orientation == "lon" || orientation == "lat" raise ArgumentError.new('Coord expects orientation to be a String argument of "lat" or "lon"') end @coordinates = coordinates @orientation = orientation end
Class Method Details
.create(arg)
Creates a new Coord from arg which may be:
LOC::Coord:: returns arg.
- String
argmust match the Regex constant
# File 'lib/resolv.rb', line 3348
def self.create(arg) case arg when Coord return arg when String unless m = Regex.match(arg) raise ArgumentError.new("not a properly formed Coord string: " + arg) end arc = (m[1].to_i * 3_600_000) + (m[2].to_i * 60_000) + (m[3].to_f * 1_000).to_i dir = m[4] lat = dir[/[NS]/] unless arc <= (lat ? 324_000_000 : 648_000_000) # (lat ? 90 : 180) * 3_600_000 raise ArgumentError.new("out of range as Coord: #{arg}") end hemi = dir[/[NE]/] ? 1 : -1 return new([arc * hemi + Bias].pack("N"), lat ? "lat" : "lon") else raise ArgumentError.new("cannot interpret as Coord: #{arg.inspect}") end end
Instance Attribute Details
#coordinates (readonly)
The raw coordinates
# File 'lib/resolv.rb', line 3386
attr_reader :coordinates
#orientation (readonly)
The orientation of the hemisphere as 'lat' or 'lon'
# File 'lib/resolv.rb', line 3390
attr_reader :orientation
Instance Method Details
#==(other)
[ GitHub ]# File 'lib/resolv.rb', line 3410
def ==(other) # :nodoc: return @coordinates == other.coordinates end
#eql?(other) ⇒ Boolean
# File 'lib/resolv.rb', line 3414
def eql?(other) # :nodoc: return self == other end
#hash
[ GitHub ]# File 'lib/resolv.rb', line 3418
def hash # :nodoc: return @coordinates.hash end
#inspect
[ GitHub ]# File 'lib/resolv.rb', line 3406
def inspect # :nodoc: return "#<#{self.class} #{self}>" end
#to_s
[ GitHub ]# File 'lib/resolv.rb', line 3392
def to_s # :nodoc: c, = @coordinates.unpack("N") val = (c -= Bias).abs val, fracsecs = val.divmod(1000) val, secs = val.divmod(60) degs, mins = val.divmod(60) hemi = if c.negative? @orientation == "lon" ? "W" : "S" else @orientation == "lat" ? "N" : "E" end format("%d %02d %02d.%03d %s", degs, mins, secs, fracsecs, hemi) end