class Marta::ElementInformation::ElementHelper

We are using helper class which can parse element attributes to our special hash format.

@note It is believed that no user will use it

Public Class Methods

method_structure(collection = false) click to toggle source

That class is also stores an empty special format hash.

# File lib/marta/element_information.rb, line 49
def self.method_structure(collection = false)
  return {'options' => {'collection' => collection},
           'positive' => {
             'self' => {
               'text'=>[], 'tag' => [], 'attributes' => {}},
              'pappy' => {
                'text'=>[], 'tag' => [], 'attributes' => {}},
              'granny' => {
                'text'=>[], 'tag' => [], 'attributes' => {}}},
            'negative' => {
              'self' => {
                'text'=>[], 'tag' => [], 'attributes' => {}},
               'pappy' => {
                 'text'=>[], 'tag' => [], 'attributes' => {}},
               'granny' => {
                 'text'=>[], 'tag' => [], 'attributes' => {}}}
              }
end
new(requestor) click to toggle source
# File lib/marta/element_information.rb, line 16
def initialize(requestor)
  @engine = requestor.engine
end

Public Instance Methods

get_element_info(element, parent_count = 0) click to toggle source

We can get data of the element or data of any parent.

# File lib/marta/element_information.rb, line 21
def get_element_info(element, parent_count = 0)
  parent = ''
  parent_count.times do
    parent = parent + '.parentElement'
  end
  result = Hash.new
  attr_script = %Q[
      var s = {};
      var attrs = arguments[0]#{parent}.attributes;
      for (var l = 0; l < attrs.length; ++l) {
          var a = attrs[l]; s[a.name] = a.value.split(" ");
      } ;
      return s;]
  tag_script = "return arguments[0]#{parent}.tagName"
  text_script = %Q[
  if (arguments[0]#{parent}.textContent == arguments[0]#{parent}.innerHTML)
     {return arguments[0]#{parent}.textContent} else {return ''};]
  result['tag'] = [@engine.execute_script(tag_script, element)]
  txt = @engine.execute_script(text_script, element)
  result['text'] = txt != '' ? [txt] : []
  result['attributes'] = @engine.execute_script(attr_script, element)
  result['attributes'].each_pair do |attribute, value|
    value.uniq!
  end
  return result
end