Module: Dustbag::Parser::Node

Defined Under Namespace

Modules: ClassMethods

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#nodeObject (readonly)

Returns the value of attribute node.



4
5
6
# File 'lib/dustbag/parser/node.rb', line 4

def node
  @node
end

#subnodesObject (readonly)

Returns the value of attribute subnodes.



4
5
6
# File 'lib/dustbag/parser/node.rb', line 4

def subnodes
  @subnodes
end

Class Method Details

.included(base) ⇒ Object



9
10
11
# File 'lib/dustbag/parser/node.rb', line 9

def self.included(base)
  base.extend(ClassMethods)
end

Instance Method Details

#initialize(node) ⇒ Object



13
14
15
16
# File 'lib/dustbag/parser/node.rb', line 13

def initialize(node)
  @node     = node
  @subnodes = {}
end

#repeated_subnodes(subnode_name) ⇒ Object



27
28
29
# File 'lib/dustbag/parser/node.rb', line 27

def repeated_subnodes(subnode_name)
  subnodes[subnode_name] ||= node.locate(subnode_name)
end

#repeated_subnodes_text(subnode_name) ⇒ Object



31
32
33
# File 'lib/dustbag/parser/node.rb', line 31

def repeated_subnodes_text(subnode_name)
  repeated_subnodes(subnode_name).map(&:text)
end

#subnode(subnode_name) ⇒ Object



23
24
25
# File 'lib/dustbag/parser/node.rb', line 23

def subnode(subnode_name)
  subnodes[subnode_name] ||= node.locate(subnode_name).first
end

#subnode_text(subnode_name) ⇒ Object



18
19
20
21
# File 'lib/dustbag/parser/node.rb', line 18

def subnode_text(subnode_name)
  subnode = subnode(subnode_name)
  subnode && subnode.text
end