Class: Dnsruby::RR::GPOS

### Home Classes Methods

### In Files

- lib/dnsruby/resource/GPOS.rb

### Parent

Dnsruby::RR

### Methods

- ::build_rdata
- ::decode_rdata
- ::new_from_data
- ::new_from_hash
- ::new_from_string
- ::valid_float?
- ::validate_float_in_range
- ::validate_floats
- ::validate_latitude
- ::validate_longitude
- #build_rdata
- #encode_rdata
- #from_data
- #from_hash
- #from_string
- #owner
- #owner=
- #rdata_to_string

### Files

- DNSSEC
- EVENTMACHINE
- EXAMPLES

### Class/Module Index

Quicksearch

- Dnsruby
- Dnsruby::Algorithms
- Dnsruby::BitMapping
- Dnsruby::Bitmap
- Dnsruby::Classes
- Dnsruby::CodeMapper
- Dnsruby::Config
- Dnsruby::DNS
- Dnsruby::DecodeError
- Dnsruby::Dnssec
- Dnsruby::Dnssec::ValidationPolicy
- Dnsruby::EncodeError
- Dnsruby::ExtendedRCode
- Dnsruby::FormErr
- Dnsruby::Header
- Dnsruby::Hosts
- Dnsruby::IPv4
- Dnsruby::IPv6
- Dnsruby::Message
- Dnsruby::Message::SecurityLevel
- Dnsruby::MetaTypes
- Dnsruby::Modes
- Dnsruby::NXDomain
- Dnsruby::NXRRSet
- Dnsruby::Name
- Dnsruby::Name::Label
- Dnsruby::NotAuth
- Dnsruby::NotImp
- Dnsruby::NotZone
- Dnsruby::Nsec3HashAlgorithms
- Dnsruby::OpCode
- Dnsruby::OtherResolvError
- Dnsruby::QTypes
- Dnsruby::Question
- Dnsruby::RCode
- Dnsruby::RR
- Dnsruby::RR::ANY
- Dnsruby::RR::CERT
- Dnsruby::RR::CERT::CertificateTypes
- Dnsruby::RR::CNAME
- Dnsruby::RR::DHCID
- Dnsruby::RR::DLV
- Dnsruby::RR::DNAME
- Dnsruby::RR::DNSKEY
- Dnsruby::RR::DS
- Dnsruby::RR::DS::DigestTypes
- Dnsruby::RR::DomainName
- Dnsruby::RR::GPOS
- Dnsruby::RR::Generic
- Dnsruby::RR::HINFO
- Dnsruby::RR::HIP
- Dnsruby::RR::IN
- Dnsruby::RR::IN::A
- Dnsruby::RR::IN::AAAA
- Dnsruby::RR::IN::AFSDB
- Dnsruby::RR::IN::PX
- Dnsruby::RR::IN::SRV
- Dnsruby::RR::IN::WKS
- Dnsruby::RR::IPSECKEY
- Dnsruby::RR::ISDN
- Dnsruby::RR::KX
- Dnsruby::RR::LOC
- Dnsruby::RR::MB
- Dnsruby::RR::MG
- Dnsruby::RR::MINFO
- Dnsruby::RR::MR
- Dnsruby::RR::MX
- Dnsruby::RR::NAPTR
- Dnsruby::RR::NS
- Dnsruby::RR::NSAP
- Dnsruby::RR::NSEC
- Dnsruby::RR::NSEC3
- Dnsruby::RR::NSEC3PARAM
- Dnsruby::RR::NXT
- Dnsruby::RR::NXT::NxtTypes
- Dnsruby::RR::NXT::TypeBitmap
- Dnsruby::RR::OPT
- Dnsruby::RR::PTR
- Dnsruby::RR::RP
- Dnsruby::RR::RRSIG
- Dnsruby::RR::RT
- Dnsruby::RR::SOA
- Dnsruby::RR::SPF
- Dnsruby::RR::SSHFP
- Dnsruby::RR::SSHFP::Algorithms
- Dnsruby::RR::SSHFP::FpTypes
- Dnsruby::RR::TKEY
- Dnsruby::RR::TSIG
- Dnsruby::RR::TXT
- Dnsruby::RR::X25
- Dnsruby::RRSet
- Dnsruby::Recursor
- Dnsruby::Refused
- Dnsruby::Resolv
- Dnsruby::ResolvError
- Dnsruby::ResolvTimeout
- Dnsruby::Resolver
- Dnsruby::Resolver::EventType
- Dnsruby::Section
- Dnsruby::SelectThread
- Dnsruby::ServFail
- Dnsruby::SingleResolver
- Dnsruby::SocketEofResolvError
- Dnsruby::TheLog
- Dnsruby::TsigError
- Dnsruby::TsigNotSignedResponseError
- Dnsruby::Types
- Dnsruby::Update
- Dnsruby::VerifyError
- Dnsruby::YXDomain
- Dnsruby::YXRRSet
- Dnsruby::ZoneReader
- Dnsruby::ZoneReader::ParseException
- Dnsruby::ZoneSerialError
- Dnsruby::ZoneTransfer
- Dnsruby::ZoneTransfer::Delta
- Base32
- Object

No matching classes.

# Dnsruby::RR::GPOS

Class for Geographic Position (GPOS) resource records.

RFC 1712 (www.ietf.org/rfc/rfc1712.txt)

### Constants

ClassValue
REQUIRED_KEYS
TypeValue

### Attributes

altitude[RW]
latitude[RW]
longitude[RW]

### Public Class Methods

build_rdata(longitude, latitude, altitude) click to toggle source

    # File lib/dnsruby/resource/GPOS.rb, line 105
    def self.build_rdata(longitude, latitude, altitude)
      binary_string = ''.force_encoding('ASCII-8BIT')

      binary_string << longitude.length.chr
      binary_string << longitude
      binary_string << latitude.length.chr
      binary_string << latitude
      binary_string << altitude.length.chr
      binary_string << altitude
      binary_string
    end

decode_rdata(message) click to toggle source

    # File lib/dnsruby/resource/GPOS.rb, line 117
    def self.decode_rdata(message)
      rdata_s = message.get_bytes.clone

      index = 0

      long_len = rdata_s[index].ord;         index += 1
      longitude = rdata_s[index, long_len];  index += long_len

      lat_len = rdata_s[index].ord;          index += 1
      latitude = rdata_s[index, lat_len];    index += lat_len

      alt_len = rdata_s[index].ord;          index += 1
      altitude = rdata_s[index, alt_len];    index += alt_len

      validate_latitude(latitude)
      validate_longitude(longitude)

      new([longitude, latitude, altitude].join(' '))  # e.g. "10.0 20.0 30.0"
    end

new_from_data(*gpos_params_data) click to toggle source

Create an instance from an ordered parameter list, e.g.: EXAMPLE_GPOS_DATA = begin

    rdata = RR::GPOS.build_rdata(EXAMPLE_LONGITUDE, EXAMPLE_LATITUDE, EXAMPLE_ALTITUDE)
    [EXAMPLE_HOSTNAME, Types::GPOS, Classes::IN, EXAMPLE_TTL, rdata.length, rdata, 0]

end self.from_data(*EXAMPLE_GPOS_DATA)

    # File lib/dnsruby/resource/GPOS.rb, line 57
    def self.new_from_data(*gpos_params_data)
      RR.new_from_data(*gpos_params_data)
    end

new_from_hash(gpos_params_hash) click to toggle source

Create an instance from a hash of parameters, e.g.:

    {
       name:       'techhumans.com',
       type:       Types::GPOS,
       ttl:        1234,
       longitude:  '10.0',
       latitude:   '20.0',
       altitude:   '30.0',
    }

Since the type is assumed to be GPOS, it will be assigned automatially, and any other value will be overwritten. Therefore, having it present in the hash is not necessary.

    # File lib/dnsruby/resource/GPOS.rb, line 38
    def self.new_from_hash(gpos_params_hash)
      gpos_params_hash[:type] = Types::GPOS
      RR.new_from_hash(gpos_params_hash)
    end

new_from_string(gpos_params_string) click to toggle source

Create an instance from a string containing parameters, e.g.: 'a.dnsruby.com. 10800 IN GPOS 10.0 20.0 30.0'

    # File lib/dnsruby/resource/GPOS.rb, line 46
    def self.new_from_string(gpos_params_string)
      RR.new_from_string(gpos_params_string)
    end

valid_float?(object) click to toggle source

    # File lib/dnsruby/resource/GPOS.rb, line 149
    def self.valid_float?(object)
      begin
        Float(object)
        true
      rescue
        false
      end
    end

validate_float_in_range(label, object, bound) click to toggle source

    # File lib/dnsruby/resource/GPOS.rb, line 158
    def self.validate_float_in_range(label, object, bound)
      number = Float(object)
      valid_range = (-Float(bound)..Float(bound))
      unless valid_range.include?(number)
        raise "Value of #{label} (#{number}) was not in the range #{valid_range}."
      end
    end

validate_floats(init_data) click to toggle source

    # File lib/dnsruby/resource/GPOS.rb, line 174
    def self.validate_floats(init_data)
      bad_float_keys = REQUIRED_KEYS.reject { |key| valid_float?(init_data[key]) }
      unless bad_float_keys.empty?
        message = "The following key value pair(s) do not have valid floats or float strings:\n"
        bad_float_keys.each do |key|
          message << "%:-12.12s => %s\n" % [init_data[key]]
        end
        raise message
      end

      validate_longitude(init_data[:longitude])
      validate_latitude(init_data[:latitude])
    end

validate_latitude(value) click to toggle source

    # File lib/dnsruby/resource/GPOS.rb, line 170
    def self.validate_latitude(value)
      validate_float_in_range('latitude',  value, 90)
    end

validate_longitude(value) click to toggle source

    # File lib/dnsruby/resource/GPOS.rb, line 166
    def self.validate_longitude(value)
      validate_float_in_range('longitude', value, 180)
    end

### Public Instance Methods

build_rdata() click to toggle source

    # File lib/dnsruby/resource/GPOS.rb, line 101
    def build_rdata
      self.class.build_rdata(longitude, latitude, altitude)
    end

encode_rdata(msg, _canonical) click to toggle source

    # File lib/dnsruby/resource/GPOS.rb, line 97
    def encode_rdata(msg, _canonical)
      msg.put_bytes(build_rdata)
    end

from_data(array) click to toggle source

    # File lib/dnsruby/resource/GPOS.rb, line 62
    def from_data(array)
      unless array.size == 3
        raise "Array size for creating GPOS record must be 3 (long, lat, alt). Array was:\n#{array.inspect}"
      end

      from_hash({
                    longitude: array[0],
                    latitude:  array[1],
                    altitude:  array[2]
                })
    end

from_hash(init_data) click to toggle source

    # File lib/dnsruby/resource/GPOS.rb, line 74
    def from_hash(init_data)
      self.class.validate_floats(init_data)
      @longitude = init_data[:longitude].to_s
      @latitude  = init_data[:latitude].to_s
      @altitude  = init_data[:altitude].to_s
      self.rdata = build_rdata
      self
    end

from_string(string) click to toggle source

    # File lib/dnsruby/resource/GPOS.rb, line 83
    def from_string(string)
      # Convert commas to spaces, then split by spaces:
      from_data(string.gsub(',', ' ').split(' '))
    end

owner() click to toggle source

'name' is used in the RR superclass, but 'owner' is the term referred to in the RFC, so we'll make owner an alias for name.

    # File lib/dnsruby/resource/GPOS.rb, line 139
    def owner
      name
    end

owner=(owner_string) click to toggle source

'name' is used in the RR superclass, but 'owner' is the term referred to in the RFC, so we'll make owner an alias for name.

    # File lib/dnsruby/resource/GPOS.rb, line 145
    def owner=(owner_string)
      self.name = owner_string
    end

rdata_to_string() click to toggle source

From the RFC:

    GPOS has the following format:

<owner> <ttl> <class> GPOS <longitude> <latitude> <altitude>

We handle the rdata, the RR superclass does the rest.

    # File lib/dnsruby/resource/GPOS.rb, line 93
    def rdata_to_string
      [longitude, latitude, altitude].join(' ')
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.