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.
3247 3248 3249 3250 3251 3252 3253 3254 3255 3256 |
# File 'lib/rubygems/vendor/resolv/lib/resolv.rb', line 3247 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
3261 3262 3263 |
# File 'lib/rubygems/vendor/resolv/lib/resolv.rb', line 3261 def coordinates @coordinates end |
#orientation ⇒ Object (readonly)
The orientation of the hemisphere as ‘lat’ or ‘lon’
3265 3266 3267 |
# File 'lib/rubygems/vendor/resolv/lib/resolv.rb', line 3265 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
3226 3227 3228 3229 3230 3231 3232 3233 3234 3235 3236 3237 3238 3239 3240 3241 3242 3243 3244 3245 |
# File 'lib/rubygems/vendor/resolv/lib/resolv.rb', line 3226 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:
3290 3291 3292 |
# File 'lib/rubygems/vendor/resolv/lib/resolv.rb', line 3290 def ==(other) # :nodoc: return @coordinates == other.coordinates end |
#eql?(other) ⇒ Boolean
:nodoc:
3294 3295 3296 |
# File 'lib/rubygems/vendor/resolv/lib/resolv.rb', line 3294 def eql?(other) # :nodoc: return self == other end |
#hash ⇒ Object
:nodoc:
3298 3299 3300 |
# File 'lib/rubygems/vendor/resolv/lib/resolv.rb', line 3298 def hash # :nodoc: return @coordinates.hash end |
#inspect ⇒ Object
:nodoc:
3286 3287 3288 |
# File 'lib/rubygems/vendor/resolv/lib/resolv.rb', line 3286 def inspect # :nodoc: return "#<#{self.class} #{self}>" end |
#to_s ⇒ Object
:nodoc:
3267 3268 3269 3270 3271 3272 3273 3274 3275 3276 3277 3278 3279 3280 3281 3282 3283 3284 |
# File 'lib/rubygems/vendor/resolv/lib/resolv.rb', line 3267 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 |