Class: Irrc::Query

Inherits:
Object
  • Object
show all
Includes:
Irr, QueryStatus, Subquery
Defined in:
lib/irrc/query.rb

Overview

Public: IRR / Whois query and result container.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Subquery

#fork, #parent, #parent=

Methods included from QueryStatus

#fail, #failed?, #succeeded?, #success

Methods included from Irr

#as_set?, #aut_num?, host, irr?, members_tag, #object, #object=, #object_type, #route_set?, route_tag, type

Constructor Details

#initialize(object, options = {}) ⇒ Query

Public: Create a new Query object.

object - IRR object to extract. (eg: as-set, route-set, aut-num object) options - The Hash options to pass to IRR. (default: [:ipv4, :ipv6])

:source   - Specify authoritative IRR source names.
            If not given, any source will be accepted. (optional)
:protocol - :ipv4, :ipv6 or [:ipv4, :ipv6]
            A String or Symbol of protcol name is acceptable. (optional)

Examples

Irrc::Query.new('AS-JPNIC', source: :jpirr, protocol: :ipv4)
Irrc::Query.new('AS-JPNIC', source: [:jpirr, :radb])


28
29
30
31
32
33
# File 'lib/irrc/query.rb', line 28

def initialize(object, options={})
  options = {protocol: [:ipv4, :ipv6]}.merge(options)
  self.sources = options[:source]
  self.protocols = options[:protocol]
  self.object = object.to_s
end

Instance Attribute Details

#protocolsObject

Returns the value of attribute protocols.



13
14
15
# File 'lib/irrc/query.rb', line 13

def protocols
  @protocols
end

#sourcesObject

Returns the value of attribute sources.



13
14
15
# File 'lib/irrc/query.rb', line 13

def sources
  @sources
end

Instance Method Details

#add_aut_num_result(autnums) ⇒ Object

Public: Register aut-num object(s) as a result.

autnums - aut-num object(s) in String. Array form is also acceptable for multiple objects.



42
43
44
45
46
47
48
49
50
# File 'lib/irrc/query.rb', line 42

def add_aut_num_result(autnums)
  @protocols.each do |protocol|
    result[protocol] ||= {}

    Array(autnums).each do |autnum|
      result[protocol][autnum] ||= []
    end
  end
end

#add_prefix_result(prefixes, autnum, protocol) ⇒ Object

Public: Register route object(s) as a result.

prefixes - route object(s) in String. Array form is also acceptable for multiple objects. autnum - Which aut-num has the route object(s). protocol - Which protocol the route object(s) is for. :ipv4 or :ipv6.

A String or Symbol of protcol name is acceptable.


58
59
60
61
62
# File 'lib/irrc/query.rb', line 58

def add_prefix_result(prefixes, autnum, protocol)
  result[protocol] ||= {}
  result[protocol][autnum] ||= []
  result[protocol][autnum] |= Array(prefixes)
end

#resultObject



35
36
37
# File 'lib/irrc/query.rb', line 35

def result
  @result ||= Struct.new(:ipv4, :ipv6).new
end