Class: ActiveDocument::Base::PartialResult

Inherits:
ActiveDocument::Base show all
Includes:
Enumerable
Defined in:
lib/ActiveDocument/active_document.rb

Overview

end inner class

Instance Attribute Summary

Attributes inherited from ActiveDocument::Base

#document, #my_attribute_namespaces, #my_default_attribute_namespaces, #my_default_namespace, #my_namespaces, #root, #uri

Instance Method Summary collapse

Methods inherited from ActiveDocument::Base

#[]=, add_attribute_namespace, add_namespace, attribute_namespaces, default_attribute_namespace, delete, find_by_word, load, #method_missing, method_missing, my_root, namespace_for_attribute, namespace_for_element, remove_attribute_namespace, remove_namespace, #save, #to_s

Methods included from ClassLevelInheritableAttributes

included

Methods inherited from Finder

co_occurrence, config, execute_attribute_finder, execute_finder, method_missing, search

Constructor Details

#initialize(nodeset, parent) ⇒ PartialResult

todo should this contain a reference to its parent?



360
361
362
363
364
365
366
367
368
369
370
371
372
# File 'lib/ActiveDocument/active_document.rb', line 360

def initialize(nodeset, parent)
  @document = nodeset
  @root =
      if nodeset.instance_of? Nokogiri::XML::Element then
        nodeset.name
      elsif nodeset.instance_of? Nokogiri::XML::NodeSet
        nodeset.first.name
      else
        nodeset[0].name
      end
  @my_namespaces = parent.class.my_namespaces
  @my_default_namespace = parent.class.my_default_namespace
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class ActiveDocument::Base

Instance Method Details

#[](index) ⇒ Object

provides access to an indexed node



385
386
387
# File 'lib/ActiveDocument/active_document.rb', line 385

def [](index)
  @document[index]
end

#childrenObject

provides access to the child nodes



380
381
382
# File 'lib/ActiveDocument/active_document.rb', line 380

def children
  @document.children
end

#each(&block) ⇒ Object



393
394
395
# File 'lib/ActiveDocument/active_document.rb', line 393

def each(& block)
  @document.each(& block)
end

#lengthObject

returns the number of Nodes in the underlying NodeSet



375
376
377
# File 'lib/ActiveDocument/active_document.rb', line 375

def length
  @document.length
end

#textObject



389
390
391
# File 'lib/ActiveDocument/active_document.rb', line 389

def text
  @document.text
end