Class: Resolv::LOC::Alt

Inherits:
Object
  • Object
show all
Defined in:
lib/resolv.rb

Overview

A Resolv::LOC::Alt

Constant Summary collapse

Regex =

Regular expression LOC Alt must match.

/\A([+-]?0*\d{1,8}(?:\.\d+)?)m\z/
Bias =

Bias to a base of 100,000m below the WGS 84 reference spheroid.

100_000_00

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(altitude) ⇒ Alt

Internal use; use self.create.



3637
3638
3639
# File 'lib/resolv.rb', line 3637

def initialize(altitude)
  @altitude = altitude
end

Instance Attribute Details

#altitude ⇒ Object (readonly)

The raw altitude



3644
3645
3646
# File 'lib/resolv.rb', line 3644

def altitude
  @altitude
end

Class Method Details

.create(arg) ⇒ Object

Creates a new LOC::Alt from arg which may be:

LOC::Alt:: returns arg.

String

arg must match the LOC::Alt::Regex constant



3618
3619
3620
3621
3622
3623
3624
3625
3626
3627
3628
3629
3630
3631
3632
3633
3634
# File 'lib/resolv.rb', line 3618

def self.create(arg)
  case arg
  when Alt
    return arg
  when String
    unless Regex =~ arg
      raise ArgumentError.new("not a properly formed Alt string: " + arg)
    end
    altitude = ($1.to_f * 100).to_i + Bias
    unless (0...0x1_0000_0000) === altitude
      raise ArgumentError.new("out of raise as Alt: #{arg}")
    end
    return new([altitude].pack("N"))
  else
    raise ArgumentError.new("cannot interpret as Alt: #{arg.inspect}")
  end
end

Instance Method Details

#==(other) ⇒ Object

:nodoc:



3655
3656
3657
# File 'lib/resolv.rb', line 3655

def ==(other) # :nodoc:
  return @altitude == other.altitude
end

#eql?(other) ⇒ Boolean

:nodoc:

Returns:

  • (Boolean)


3659
3660
3661
# File 'lib/resolv.rb', line 3659

def eql?(other) # :nodoc:
  return self == other
end

#hash ⇒ Object

:nodoc:



3663
3664
3665
# File 'lib/resolv.rb', line 3663

def hash # :nodoc:
  return @altitude.hash
end

#inspect ⇒ Object

:nodoc:



3651
3652
3653
# File 'lib/resolv.rb', line 3651

def inspect # :nodoc:
  return "#<#{self.class} #{self}>"
end

#to_s ⇒ Object

:nodoc:



3646
3647
3648
3649
# File 'lib/resolv.rb', line 3646

def to_s # :nodoc:
  a, = @altitude.unpack("N")
  return "#{(a - Bias).fdiv(100)}m"
end