Class: JsshDOMNode

Inherits:
JsshObject show all
Defined in:
lib/vapir-firefox/jssh_socket.rb

Overview

represents a node on the DOM. not substantially from JsshObject, but #inspect is more informative, and #dump is defined for extensive debug info.

This class is mostly useful for debug, not used anywhere in production at the moment.

Instance Attribute Summary

Attributes inherited from JsshObject

#debug_name, #function_result, #jssh_socket, #ref

Instance Method Summary collapse

Methods inherited from JsshObject

#%, #*, #+, #-, #/, #<, #<=, #==, #>, #>=, #[], #[]=, always_define_methods, always_define_methods=, #assign, #assign_expr, #assign_or_call_or_val_or_object_by_suffix, #attr, #binary_operator, #call, #define_methods!, #implemented_interfaces, #initialize, #instanceof, #invoke, #invoke?, #method_missing, #new, #object_respond_to?, #object_type, #pass, #respond_to?, #store, #store_rand_object_key, #store_rand_temp, #sub, #to_array, #to_dom, #to_hash, #to_js_array, #to_js_hash, #to_js_hash_safe, #to_ruby_array, #to_ruby_hash, #triple_equals, #type, #val, #val_or_object, #val_str

Constructor Details

This class inherits a constructor from JsshObject

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class JsshObject

Instance Method Details

#dump(options = {}) ⇒ Object

returns a string (most useful when written to STDOUT or to a file) consisting of this dom node and its child nodes, recursively. each node is one line and depth is indicated by spacing.

call #dump(:recurse => n) to recurse down only n levels. default is to recurse all the way down the dom tree.



1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
# File 'lib/vapir-firefox/jssh_socket.rb', line 1355

def dump(options={})
  options={:recurse => nil, :level => 0}.merge(options)
  next_options=options.merge(:recurse => options[:recurse] && (options[:recurse]-1), :level => options[:level]+1)
  result=(" "*options[:level]*2)+self.inspect+"\n"
  if options[:recurse]==0
    result+=(" "*next_options[:level]*2)+"...\n"
  else 
    self.childNodes.to_array.each do |child|
      result+=child.to_dom.dump(next_options)
    end
  end
  result
end

#inspectObject

returns a string with a bunch of information about this dom node



1335
1336
1337
# File 'lib/vapir-firefox/jssh_socket.rb', line 1335

def inspect
  "\#<#{self.class.name} #{inspect_stuff.map{|(k,v)| "#{k}=#{v.inspect}"}.join(', ')}>"
end

#inspect_stuffObject

:nodoc:



1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
# File 'lib/vapir-firefox/jssh_socket.rb', line 1324

def inspect_stuff # :nodoc:
  [:nodeName, :nodeType, :nodeValue, :tagName, :textContent, :id, :name, :value, :type, :className, :hidden].map do |attrn|
    attr=attr(attrn)
    if ['undefined','null'].include?(attr.type)
      nil
    else
      [attrn, attr.val_or_object(:error_on_undefined => false)]
    end
  end.compact
end

#pretty_print(pp) ⇒ Object

:nodoc:



1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
# File 'lib/vapir-firefox/jssh_socket.rb', line 1338

def pretty_print(pp) # :nodoc:
  pp.object_address_group(self) do
    pp.seplist(inspect_stuff, lambda { pp.text ',' }) do |attr_val|
      pp.breakable ' '
      pp.group(0) do
        pp.text attr_val.first.to_s
        pp.text ': '
        #pp.breakable
        pp.text attr_val.last.inspect
      end
    end
  end
end