Class: Onion::RouterList

Inherits:
Object
  • Object
show all
Defined in:
lib/onion/elements/router_list.rb

Overview

Onion::RouterList is a list of Onion::Router objects.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(text) ⇒ RouterList

Returns a new instance of RouterList.



5
6
7
8
9
10
11
12
13
14
15
16
# File 'lib/onion/elements/router_list.rb', line 5

def initialize(text)
  if text.blank?
    @routers = []
    return self
  end
  parser = Onion::RouterStatusesParser.new
  if nodes  = parser.parse(text)
    @routers = nodes.routers
  else
    raise Exception, "Couldn't parse #{text} b/c #{parser.failure_reason}."
  end
end

Instance Attribute Details

#routersObject (readonly)

Returns the value of attribute routers.



4
5
6
# File 'lib/onion/elements/router_list.rb', line 4

def routers
  @routers
end

Instance Method Details

#exitsObject

Returns the routers that are exit routers.



24
25
26
# File 'lib/onion/elements/router_list.rb', line 24

def exits
  @routers.select { |r| r.exit? }
end

#guardsObject

Returns the routers that are guard routers.



19
20
21
# File 'lib/onion/elements/router_list.rb', line 19

def guards
  @routers.select { |r| r.guard? }
end

#middlemenObject

Returns the routers that are neither guard or exit routers.



29
30
31
# File 'lib/onion/elements/router_list.rb', line 29

def middlemen
  @routers.reject { |r| r.guard? or r.exit? }
end