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.
2679 2680 2681 2682 2683 2684 2685 2686 2687 2688 |
# File 'lib/resolv.rb', line 2679 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
2693 2694 2695 |
# File 'lib/resolv.rb', line 2693 def coordinates @coordinates end |
#orientation ⇒ Object (readonly)
The orientation of the hemisphere as ‘lat’ or ‘lon’
2697 2698 2699 |
# File 'lib/resolv.rb', line 2697 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
2660 2661 2662 2663 2664 2665 2666 2667 2668 2669 2670 2671 2672 2673 2674 2675 2676 2677 |
# File 'lib/resolv.rb', line 2660 def self.create(arg) case arg when Coord return arg when String coordinates = '' if Regex =~ arg && $1<180 hemi = ($4[/([NE])/,1]) || ($4[/([SW])/,1]) ? 1 : -1 coordinates = [(($1.to_i*(36e5))+($2.to_i*(6e4))+($3.to_f*(1e3)))*hemi+(2**31)].pack("N") (orientation ||= '') << $4[[/NS/],1] ? '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:
2722 2723 2724 |
# File 'lib/resolv.rb', line 2722 def ==(other) # :nodoc: return @coordinates == other.coordinates end |
#eql?(other) ⇒ Boolean
:nodoc:
2726 2727 2728 |
# File 'lib/resolv.rb', line 2726 def eql?(other) # :nodoc: return self == other end |
#hash ⇒ Object
:nodoc:
2730 2731 2732 |
# File 'lib/resolv.rb', line 2730 def hash # :nodoc: return @coordinates.hash end |
#inspect ⇒ Object
:nodoc:
2718 2719 2720 |
# File 'lib/resolv.rb', line 2718 def inspect # :nodoc: return "#<#{self.class} #{self.to_s}>" end |
#to_s ⇒ Object
:nodoc:
2699 2700 2701 2702 2703 2704 2705 2706 2707 2708 2709 2710 2711 2712 2713 2714 2715 2716 |
# File 'lib/resolv.rb', line 2699 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 |