class Graph::NodeArray

An array of Node objects

Public Class Methods

new(li) click to toggle source

Create a new NodeArray from an existing Array. @param li [Array]

Calls superclass method
# File lib/graph.rb, line 132
def initialize(li)
    nodes = li.map { |n| n.is_a?(Node) ? n : Node.new(n) }
    super(nodes)
    @defaults = {}
end

Public Instance Methods

push(n) click to toggle source

Add the given node at the end of the list @param n [Node] @return [NodeArray]

Calls superclass method
# File lib/graph.rb, line 152
def push(n)
    if (!n.is_a?(Hash) && !n.is_a?(Node))
        raise TypeError.new "#{n.inspect} is not an Hash nor a Node!"
    end

    n = Node.new(n) if (n.is_a?(Hash))

    super(n.clone.update(@defaults))
end
set_default(dict) click to toggle source

Set some default values for current elements. @note This method can be called multiple times. @param dict [Hash] @return [NodeArray] @example Set all nodes’s ‘created-at’ value to ‘2012-05-03’

myNodeList.set_default({'created-at'=>'2012-05-03'})
# File lib/graph.rb, line 144
def set_default(dict)
    @defaults.update(dict)
    self.map! { |e| e.update(@defaults) }
end