Sha256: 5b9e68da45f2dd8865cff3752a4683c951fafc1d547d557a9fb4a4734a1d8baa

Contents?: true

Size: 608 Bytes

Versions: 7

Compression:

Stored size: 608 Bytes

Contents

class Ld::Nodes
  attr_accessor :nodes

  def initialize nodes = []
    @nodes = nodes
  end

  def << node
    @nodes << node
  end

  def where option
    sql = ""
    if option.instance_of?(String)
      sql = option
    elsif option.instance_of?(Hash)
      sql = option.map{|k,v| "node.#{k} == #{v.instance_of?(String) ? "'#{v}'" : "#{v}"}"}.join(" and ")
    end
    @nodes.map{|node| if(eval(sql));node;end}.compact
  end

  def find id
    @nodes.each{|node| return node if node.id == id}
  end

  def size
    @nodes.size
  end

  def sort_by_depth
    @nodes.sort{|a,b| a.depth - b.depth}
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
ld-0.1.9 lib/ld/nodes.rb
ld-0.1.8 lib/ld/nodes.rb
ld-0.1.7 lib/ld/nodes.rb
ld-0.1.6 lib/ld/nodes.rb
ld-0.1.2 lib/ld/nodes.rb
ld-0.1.1 lib/ld/nodes.rb
ld-0.1.0 lib/ld/nodes.rb