Class: Gem::Resolv::LOC::Coord
- Inherits:
-
Object
- Object
- Gem::Resolv::LOC::Coord
- Defined in:
- lib/rubygems/vendor/resolv/lib/resolv.rb
Overview
A Gem::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.
3316 3317 3318 3319 3320 3321 3322 3323 3324 3325 |
# File 'lib/rubygems/vendor/resolv/lib/resolv.rb', line 3316 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
3330 3331 3332 |
# File 'lib/rubygems/vendor/resolv/lib/resolv.rb', line 3330 def coordinates @coordinates end |
#orientation ⇒ Object (readonly)
The orientation of the hemisphere as ‘lat’ or ‘lon’
3334 3335 3336 |
# File 'lib/rubygems/vendor/resolv/lib/resolv.rb', line 3334 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
3295 3296 3297 3298 3299 3300 3301 3302 3303 3304 3305 3306 3307 3308 3309 3310 3311 3312 3313 3314 |
# File 'lib/rubygems/vendor/resolv/lib/resolv.rb', line 3295 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:
3359 3360 3361 |
# File 'lib/rubygems/vendor/resolv/lib/resolv.rb', line 3359 def ==(other) # :nodoc: return @coordinates == other.coordinates end |
#eql?(other) ⇒ Boolean
:nodoc:
3363 3364 3365 |
# File 'lib/rubygems/vendor/resolv/lib/resolv.rb', line 3363 def eql?(other) # :nodoc: return self == other end |
#hash ⇒ Object
:nodoc:
3367 3368 3369 |
# File 'lib/rubygems/vendor/resolv/lib/resolv.rb', line 3367 def hash # :nodoc: return @coordinates.hash end |
#inspect ⇒ Object
:nodoc:
3355 3356 3357 |
# File 'lib/rubygems/vendor/resolv/lib/resolv.rb', line 3355 def inspect # :nodoc: return "#<#{self.class} #{self}>" end |
#to_s ⇒ Object
:nodoc:
3336 3337 3338 3339 3340 3341 3342 3343 3344 3345 3346 3347 3348 3349 3350 3351 3352 3353 |
# File 'lib/rubygems/vendor/resolv/lib/resolv.rb', line 3336 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 |