Class: Irrc::Query
- Inherits:
-
Object
- Object
- Irrc::Query
- Includes:
- Irr, QueryStatus, Subquery
- Defined in:
- lib/irrc/query.rb
Overview
Public: IRR / Whois query and result container.
Instance Attribute Summary collapse
-
#protocols ⇒ Object
readonly
Returns the value of attribute protocols.
-
#sources ⇒ Object
readonly
Returns the value of attribute sources.
Instance Method Summary collapse
-
#add_aut_num_result(autnums) ⇒ Object
Public: Register aut-num object(s) as a result.
-
#add_prefix_result(prefixes, autnum, protocol) ⇒ Object
Public: Register route object(s) as a result.
-
#initialize(object, options = {}) ⇒ Query
constructor
Public: Create a new Query object.
- #result ⇒ Object
Methods included from Subquery
#add_child, #ancestor_object?, #ancestor_objects, #children, #delete_child, #fork, #parent, #parent=, #root, #root?
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, ={}) = {protocol: [:ipv4, :ipv6]}.merge() self.sources = [:source] self.protocols = [:protocol] self.object = object.to_s end |
Instance Attribute Details
#protocols ⇒ Object
Returns the value of attribute protocols.
13 14 15 |
# File 'lib/irrc/query.rb', line 13 def protocols @protocols end |
#sources ⇒ Object
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 51 52 |
# File 'lib/irrc/query.rb', line 42 def add_aut_num_result(autnums) result = root.result @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.
60 61 62 63 64 65 66 |
# File 'lib/irrc/query.rb', line 60 def add_prefix_result(prefixes, autnum, protocol) result = root.result result[protocol] ||= {} result[protocol][autnum] ||= [] result[protocol][autnum].push *Array(prefixes) end |
#result ⇒ Object
35 36 37 |
# File 'lib/irrc/query.rb', line 35 def result @result ||= Struct.new(:ipv4, :ipv6).new end |