Class: Moxml::NodeSet
- Inherits:
-
Object
- Object
- Moxml::NodeSet
- Includes:
- Enumerable
- Defined in:
- lib/moxml/node_set.rb
Instance Attribute Summary collapse
-
#context ⇒ Object
readonly
Returns the value of attribute context.
-
#nodes ⇒ Object
readonly
Returns the value of attribute nodes.
Instance Method Summary collapse
- #+(other) ⇒ Object
- #==(other) ⇒ Object
- #[](index) ⇒ Object
- #each ⇒ Object
- #empty? ⇒ Boolean
- #first ⇒ Object
-
#initialize(nodes, context) ⇒ NodeSet
constructor
A new instance of NodeSet.
- #last ⇒ Object
- #remove ⇒ Object
- #size ⇒ Object (also: #length)
- #text ⇒ Object
- #to_a ⇒ Object
Constructor Details
#initialize(nodes, context) ⇒ NodeSet
9 10 11 12 |
# File 'lib/moxml/node_set.rb', line 9 def initialize(nodes, context) @nodes = Array(nodes) @context = context end |
Instance Attribute Details
#context ⇒ Object (readonly)
Returns the value of attribute context.
7 8 9 |
# File 'lib/moxml/node_set.rb', line 7 def context @context end |
#nodes ⇒ Object (readonly)
Returns the value of attribute nodes.
7 8 9 |
# File 'lib/moxml/node_set.rb', line 7 def nodes @nodes end |
Instance Method Details
#+(other) ⇒ Object
51 52 53 |
# File 'lib/moxml/node_set.rb', line 51 def +(other) self.class.new(nodes + other.nodes, context) end |
#==(other) ⇒ Object
55 56 57 58 59 60 61 |
# File 'lib/moxml/node_set.rb', line 55 def ==(other) self.class == other.class && length == other.length && nodes.each_with_index.all? do |node, index| Node.wrap(node, context) == other[index] end end |
#[](index) ⇒ Object
21 22 23 24 25 26 27 28 |
# File 'lib/moxml/node_set.rb', line 21 def [](index) case index when Integer Node.wrap(nodes[index], context) when Range NodeSet.new(nodes[index], context) end end |
#each ⇒ Object
14 15 16 17 18 19 |
# File 'lib/moxml/node_set.rb', line 14 def each return to_enum(:each) unless block_given? nodes.each { |node| yield Node.wrap(node, context) } self end |
#empty? ⇒ Boolean
38 39 40 |
# File 'lib/moxml/node_set.rb', line 38 def empty? nodes.empty? end |
#first ⇒ Object
30 31 32 |
# File 'lib/moxml/node_set.rb', line 30 def first Node.wrap(nodes.first, context) end |
#last ⇒ Object
34 35 36 |
# File 'lib/moxml/node_set.rb', line 34 def last Node.wrap(nodes.last, context) end |
#remove ⇒ Object
67 68 69 70 |
# File 'lib/moxml/node_set.rb', line 67 def remove each(&:remove) self end |
#size ⇒ Object Also known as: length
42 43 44 |
# File 'lib/moxml/node_set.rb', line 42 def size nodes.size end |
#text ⇒ Object
63 64 65 |
# File 'lib/moxml/node_set.rb', line 63 def text map(&:text).join end |
#to_a ⇒ Object
47 48 49 |
# File 'lib/moxml/node_set.rb', line 47 def to_a map { |node| node } end |