Class: Tinet::Switch

Inherits:
Object
  • Object
show all
Defined in:
lib/tinet/switch.rb

Defined Under Namespace

Classes: Interfase

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, interfaces) ⇒ Switch

Returns a new instance of Switch.

Parameters:



18
19
20
21
22
# File 'lib/tinet/switch.rb', line 18

def initialize(name, interfaces)
  @name = name
  @interfaces = interfaces
  interfaces.each { |interface| interface.switch = self }
end

Instance Attribute Details

#interfacesObject (readonly)

Returns the value of attribute interfaces.



14
15
16
# File 'lib/tinet/switch.rb', line 14

def interfaces
  @interfaces
end

#nameObject (readonly)

Returns the value of attribute name.



14
15
16
# File 'lib/tinet/switch.rb', line 14

def name
  @name
end

Class Method Details

.parse(switch_hash) ⇒ Tinet::Switch

Parameters:

  • switch_hash (Hash)

Returns:

Raises:



5
6
7
8
9
10
11
12
# File 'lib/tinet/switch.rb', line 5

def self.parse(switch_hash)
  name, interfaces = switch_hash['name'], switch_hash['interfaces']
  raise InvalidYAMLError, "Switch name is missing" if name.nil? || name.empty?
  raise InvalidYAMLError, "Switch interfaces must be array" unless interfaces.is_a?(Array)

  interfaces = interfaces.map { |interface| Interfase.parse(interface) }
  self.new(name, interfaces)
end