Class: GoNodes::NodeList
Class Method Summary collapse
Instance Method Summary collapse
- #==(other_node_list) ⇒ Object
- #[](node_name) ⇒ Object
-
#initialize ⇒ NodeList
constructor
A new instance of NodeList.
- #populate_with_count(node_count) ⇒ Object
- #populate_with_names(node_names) ⇒ Object
- #to_s ⇒ Object
Methods inherited from Set
Constructor Details
#initialize ⇒ NodeList
Returns a new instance of NodeList.
5 6 7 8 |
# File 'lib/gonodes/node_list.rb', line 5 def initialize @nodes = Set.new super(@nodes) end |
Class Method Details
.new_with_count(count) ⇒ Object
14 15 16 17 18 |
# File 'lib/gonodes/node_list.rb', line 14 def self.new_with_count(count) node_list = NodeList.new node_list.populate_with_count(count) node_list end |
.new_with_names(names) ⇒ Object
20 21 22 23 24 |
# File 'lib/gonodes/node_list.rb', line 20 def self.new_with_names(names) node_list = NodeList.new node_list.populate_with_names(names) node_list end |
Instance Method Details
#==(other_node_list) ⇒ Object
30 31 32 |
# File 'lib/gonodes/node_list.rb', line 30 def ==(other_node_list) self.sort == other_node_list.sort end |
#[](node_name) ⇒ Object
26 27 28 |
# File 'lib/gonodes/node_list.rb', line 26 def [](node_name) @nodes.select{|node,_| node.name == node_name}.first end |
#populate_with_count(node_count) ⇒ Object
34 35 36 37 38 39 40 41 42 |
# File 'lib/gonodes/node_list.rb', line 34 def populate_with_count(node_count) return unless node_count alpha = "A" @nodes.clear node_count.times do @nodes << Node.new(alpha) alpha = alpha.succ end end |
#populate_with_names(node_names) ⇒ Object
44 45 46 47 48 |
# File 'lib/gonodes/node_list.rb', line 44 def populate_with_names(node_names) return unless node_names @nodes.clear node_names.each { |name| @nodes << Node.new(name)} end |
#to_s ⇒ Object
10 11 12 |
# File 'lib/gonodes/node_list.rb', line 10 def to_s @nodes.to_a.join(", ") end |