class ReaPack::Index::NamedNode
Constants
- NAME_ATTR
Attributes
node[R]
Public Class Methods
create(name, parent)
click to toggle source
# File lib/reapack/index/named_node.rb, line 36 def self.create(name, parent) node = Nokogiri::XML::Node.new tag, parent.document node[NAME_ATTR] = name node.parent = parent instance = new node instance.instance_variable_set :@is_new, true instance.instance_variable_set :@dirty, true instance end
fetch(name, parent, create)
click to toggle source
# File lib/reapack/index/named_node.rb, line 24 def self.fetch(name, parent, create) return unless parent instance = find_one name, parent if create instance ||= self.create name, parent end instance end
find_all(parent)
click to toggle source
# File lib/reapack/index/named_node.rb, line 18 def self.find_all(parent) parent.element_children .select {|node| node.name == tag } .map {|node| self.new node } end
find_one(name, parent)
click to toggle source
# File lib/reapack/index/named_node.rb, line 10 def self.find_one(name, parent) node = parent.element_children.find {|node| node.name == tag && node[NAME_ATTR] == name } self.new node if node end
new(node)
click to toggle source
# File lib/reapack/index/named_node.rb, line 48 def initialize(node) @node = node end
tag()
click to toggle source
# File lib/reapack/index/named_node.rb, line 5 def self.tag; raise "@tag is unset" unless @tag @tag end
Public Instance Methods
children(tag)
click to toggle source
# File lib/reapack/index/named_node.rb, line 69 def children(tag) @node.element_children.select {|node| node.name == tag } end
empty?()
click to toggle source
# File lib/reapack/index/named_node.rb, line 61 def empty? @node.element_children.empty? end
is_new?()
click to toggle source
# File lib/reapack/index/named_node.rb, line 54 def is_new?; !!@is_new; end
modified?()
click to toggle source
# File lib/reapack/index/named_node.rb, line 55 def modified?; !!@dirty; end
name()
click to toggle source
# File lib/reapack/index/named_node.rb, line 57 def name @node[NAME_ATTR] end
remove()
click to toggle source
# File lib/reapack/index/named_node.rb, line 65 def remove @node.remove end