Class: Resolv::LOC::Coord
- Inherits:
-
Object
- Object
- Resolv::LOC::Coord
- Defined in:
- lib/resolv.rb
Overview
A Resolv::LOC::Coord
Constant Summary collapse
- Regex =
/^(\d+)\s(\d+)\s(\d+\.\d+)\s([NESW])$/
Instance Attribute Summary collapse
-
#coordinates ⇒ Object
readonly
The raw coordinates.
-
#orientation ⇒ Object
readonly
The orientation of the hemisphere as ‘lat’ or ‘lon’.
Class Method Summary collapse
-
.create(arg) ⇒ Object
Creates a new LOC::Coord from
arg
which may be:.
Instance Method Summary collapse
-
#==(other) ⇒ Object
:nodoc:.
-
#eql?(other) ⇒ Boolean
:nodoc:.
-
#hash ⇒ Object
:nodoc:.
-
#initialize(coordinates, orientation) ⇒ Coord
constructor
A new instance of Coord.
-
#inspect ⇒ Object
:nodoc:.
-
#to_s ⇒ Object
:nodoc:.
Constructor Details
#initialize(coordinates, orientation) ⇒ Coord
Returns a new instance of Coord.
3313 3314 3315 3316 3317 3318 3319 3320 3321 3322 |
# File 'lib/resolv.rb', line 3313 def initialize(coordinates,orientation) unless coordinates.kind_of?(String) raise ArgumentError.new("Coord must be a 32bit unsigned integer in hex format: #{coordinates.inspect}") end unless orientation.kind_of?(String) && orientation[/^lon$|^lat$/] raise ArgumentError.new('Coord expects orientation to be a String argument of "lat" or "lon"') end @coordinates = coordinates @orientation = orientation end |
Instance Attribute Details
#coordinates ⇒ Object (readonly)
The raw coordinates
3327 3328 3329 |
# File 'lib/resolv.rb', line 3327 def coordinates @coordinates end |
#orientation ⇒ Object (readonly)
The orientation of the hemisphere as ‘lat’ or ‘lon’
3331 3332 3333 |
# File 'lib/resolv.rb', line 3331 def orientation @orientation end |
Class Method Details
.create(arg) ⇒ Object
Creates a new LOC::Coord from arg
which may be:
- LOC::Coord
-
returns
arg
. - String
-
arg
must match the LOC::Coord::Regex constant
3292 3293 3294 3295 3296 3297 3298 3299 3300 3301 3302 3303 3304 3305 3306 3307 3308 3309 3310 3311 |
# File 'lib/resolv.rb', line 3292 def self.create(arg) case arg when Coord return arg when String coordinates = '' if Regex =~ arg && $1.to_f < 180 m = $~ hemi = (m[4][/[NE]/]) || (m[4][/[SW]/]) ? 1 : -1 coordinates = [ ((m[1].to_i*(36e5)) + (m[2].to_i*(6e4)) + (m[3].to_f*(1e3))) * hemi+(2**31) ].pack("N") orientation = m[4][/[NS]/] ? 'lat' : 'lon' else raise ArgumentError.new("not a properly formed Coord string: " + arg) end return Coord.new(coordinates,orientation) else raise ArgumentError.new("cannot interpret as Coord: #{arg.inspect}") end end |
Instance Method Details
#==(other) ⇒ Object
:nodoc:
3356 3357 3358 |
# File 'lib/resolv.rb', line 3356 def ==(other) # :nodoc: return @coordinates == other.coordinates end |
#eql?(other) ⇒ Boolean
:nodoc:
3360 3361 3362 |
# File 'lib/resolv.rb', line 3360 def eql?(other) # :nodoc: return self == other end |
#hash ⇒ Object
:nodoc:
3364 3365 3366 |
# File 'lib/resolv.rb', line 3364 def hash # :nodoc: return @coordinates.hash end |
#inspect ⇒ Object
:nodoc:
3352 3353 3354 |
# File 'lib/resolv.rb', line 3352 def inspect # :nodoc: return "#<#{self.class} #{self}>" end |
#to_s ⇒ Object
:nodoc:
3333 3334 3335 3336 3337 3338 3339 3340 3341 3342 3343 3344 3345 3346 3347 3348 3349 3350 |
# File 'lib/resolv.rb', line 3333 def to_s # :nodoc: c = @coordinates.unpack("N").join.to_i val = (c - (2**31)).abs fracsecs = (val % 1e3).to_i.to_s val = val / 1e3 secs = (val % 60).to_i.to_s val = val / 60 mins = (val % 60).to_i.to_s degs = (val / 60).to_i.to_s posi = (c >= 2**31) case posi when true hemi = @orientation[/^lat$/] ? "N" : "E" else hemi = @orientation[/^lon$/] ? "W" : "S" end return degs << " " << mins << " " << secs << "." << fracsecs << " " << hemi end |