Class: ResolvFiber::LOC::Coord
- Inherits:
-
Object
- Object
- ResolvFiber::LOC::Coord
- Defined in:
- lib/resolv_fiber.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
argwhich 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.
2791 2792 2793 2794 2795 2796 2797 2798 2799 2800 |
# File 'lib/resolv_fiber.rb', line 2791 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
2805 2806 2807 |
# File 'lib/resolv_fiber.rb', line 2805 def coordinates @coordinates end |
#orientation ⇒ Object (readonly)
The orientation of the hemisphere as ‘lat’ or ‘lon’
2809 2810 2811 |
# File 'lib/resolv_fiber.rb', line 2809 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
-
argmust match the LOC::Coord::Regex constant
2770 2771 2772 2773 2774 2775 2776 2777 2778 2779 2780 2781 2782 2783 2784 2785 2786 2787 2788 2789 |
# File 'lib/resolv_fiber.rb', line 2770 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:
2834 2835 2836 |
# File 'lib/resolv_fiber.rb', line 2834 def ==(other) # :nodoc: return @coordinates == other.coordinates end |
#eql?(other) ⇒ Boolean
:nodoc:
2838 2839 2840 |
# File 'lib/resolv_fiber.rb', line 2838 def eql?(other) # :nodoc: return self == other end |
#hash ⇒ Object
:nodoc:
2842 2843 2844 |
# File 'lib/resolv_fiber.rb', line 2842 def hash # :nodoc: return @coordinates.hash end |
#inspect ⇒ Object
:nodoc:
2830 2831 2832 |
# File 'lib/resolv_fiber.rb', line 2830 def inspect # :nodoc: return "#<#{self.class} #{self}>" end |
#to_s ⇒ Object
:nodoc:
2811 2812 2813 2814 2815 2816 2817 2818 2819 2820 2821 2822 2823 2824 2825 2826 2827 2828 |
# File 'lib/resolv_fiber.rb', line 2811 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 |