Class: BGPView::Asn

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

Constant Summary collapse

@@cache =
{}

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(number, name = '', detail: false) ⇒ Asn

Returns a new instance of Asn.



17
18
19
20
21
22
23
24
25
26
27
# File 'lib/bgpview/asn.rb', line 17

def initialize(number, name = '', detail: false)
  BGPView::Number.check(number)

  @number = number
  @name = name
  @data = {}

  call_api if detail

  @@cache[number] = self
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args) ⇒ Object



37
38
39
40
41
42
43
# File 'lib/bgpview/asn.rb', line 37

def method_missing(method, *args)
  if data.key?(method.to_sym)
    data[method.to_sym]
  else
    super
  end
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



15
16
17
# File 'lib/bgpview/asn.rb', line 15

def name
  @name
end

#numberObject (readonly)

Returns the value of attribute number.



15
16
17
# File 'lib/bgpview/asn.rb', line 15

def number
  @number
end

Class Method Details

.find(number) ⇒ Object



29
30
31
# File 'lib/bgpview/asn.rb', line 29

def self.find(number)
  @@cache.key?(number) ? @@cache[number] : new(number, detail: true)
end

.find_or_create(number, name) ⇒ Object



33
34
35
# File 'lib/bgpview/asn.rb', line 33

def self.find_or_create(number, name)
  @@cache.key?(number) ? @@cache[number] : new(number, name)
end

Instance Method Details

#downstreamsObject



49
50
51
# File 'lib/bgpview/asn.rb', line 49

def downstreams
  BGPView::Downstreams.find(@number)
end

#peersObject



53
54
55
# File 'lib/bgpview/asn.rb', line 53

def peers
  BGPView::Peers.find(@number)
end

#prefixesObject



57
58
59
# File 'lib/bgpview/asn.rb', line 57

def prefixes
  BGPView::Prefixes.find(@number)
end

#upstreamsObject



45
46
47
# File 'lib/bgpview/asn.rb', line 45

def upstreams
  BGPView::Upstreams.find(@number)
end