Class: Rubyvis::Dom
Overview
Constructs a DOM operator for the specified map. This constructor should not be invoked directly; use pv.dom instead.
transformation of a hierarchical JavaScript object (such as a JSON map) to a W3C Document Object Model hierarchy. For more information on which attributes and methods from the specification are supported, see pv.Dom.Node.
<p>Leaves in the map are determined using an associated leaf function; see #leaf. By default, leaves are any value whose type is not “object”, such as numbers or strings.
Defined Under Namespace
Classes: Node
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(map) ⇒ Dom
constructor
A new instance of Dom.
-
#leaf(f = nil) ⇒ Object
Sets or gets the leaf function for this DOM operator.
-
#nodes ⇒ Object
Applies the DOM operator, returning the array of all nodes in preorder traversal.
-
#root(node_name = nil) ⇒ Object
Applies the DOM operator, returning the root node.
- #root_recurse(map) ⇒ Object
Constructor Details
#initialize(map) ⇒ Dom
Returns a new instance of Dom.
28 29 30 31 |
# File 'lib/rubyvis/dom.rb', line 28 def initialize(map) @_map=map @leaf=lambda {|n| !n.respond_to? :each } end |
Class Method Details
Instance Method Details
#leaf(f = nil) ⇒ Object
Sets or gets the leaf function for this DOM operator. The leaf function identifies which values in the map are leaves, and which are internal nodes. By default, objects are considered internal nodes, and primitives (such as numbers and strings) are considered leaves.
39 40 41 42 43 44 45 |
# File 'lib/rubyvis/dom.rb', line 39 def leaf(f=nil) if !f.nil? @leaf=f self end @leaf end |
#nodes ⇒ Object
Applies the DOM operator, returning the array of all nodes in preorder traversal.
65 66 67 |
# File 'lib/rubyvis/dom.rb', line 65 def nodes self.root.nodes end |