Class: IEParserTopDown

Inherits:
Object
  • Object
show all
Defined in:
lib/ieparser_extension.rb

Instance Method Summary collapse

Constructor Details

#initialize(win32ole_object, xpath_expression) ⇒ IEParserTopDown

Returns a new instance of IEParserTopDown.



31
32
33
34
# File 'lib/ieparser_extension.rb', line 31

def initialize(win32ole_object,xpath_expression)
  @win32ole_object = win32ole_object
  @finder_info = Tokenize.new(xpath_expression).populate
end

Instance Method Details

#calculate_index(elements) ⇒ Object



87
88
89
90
91
92
93
# File 'lib/ieparser_extension.rb', line 87

def calculate_index(elements)
  if elements[:element_index] == 0
    index = elements[:element_index]
  else
    index = elements[:element_index] - 1
  end
end

#find_matching_childnode(current_node, element_to_find) ⇒ Object



108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
# File 'lib/ieparser_extension.rb', line 108

def find_matching_childnode(current_node,element_to_find)
  elements = split_with_selector(element_to_find)

  child_array = []
  
  begin
    current_node.childnodes.each{|child|
      if child.nodename == elements[:element_name]
        #~ puts "#{elements[:element_name]} : #{child.nodename}"
        child_array << child
      end
    }
  rescue
  end

  index = calculate_index(elements)
  child_array[index]
end

#find_potential_matching_nodes(current_node, element_array) ⇒ Object



59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/ieparser_extension.rb', line 59

def find_potential_matching_nodes(current_node,element_array)
  marker = nil
  if element_array.size == 0
    marker = current_node
  else
    element_array.each_with_index{|element,i|
      element = element_array[i + 1] unless element_array[i + 1].nil?
      found = find_matching_childnode(current_node,element)
      if found
        current_node = found
      else
        break
      end
      marker = current_node
    }
  end 
  marker    
end

#find_starting_current_node_with_selector(element_to_find) ⇒ Object



78
79
80
81
82
83
84
85
# File 'lib/ieparser_extension.rb', line 78

def find_starting_current_node_with_selector(element_to_find)
  elements = split_with_selector(element_to_find)
  index = calculate_index(elements).to_s
  begin
    @win32ole_object.document.getElementsByTagName(elements[:element_name])[index]
  rescue
  end
end

#find_top_downObject



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/ieparser_extension.rb', line 40

def find_top_down
  current_node = nil
  
  if path_has_id?
    id = @finder_info.tag_id
#      if has_frames?
#        current_node = find_starting_id_node_with_frames(id)
#      else
      current_node = @win32ole_object.document.getElementById(id)
#      end
  else
    element = @finder_info.path.first.upcase
    current_node = find_starting_current_node_with_selector(element)
  end
 
  element_array = @finder_info.path
  find_potential_matching_nodes(current_node,element_array)
end

#select_nodesObject



36
37
38
# File 'lib/ieparser_extension.rb', line 36

def select_nodes
  [find_top_down]
end

#split_with_selector(element_to_find) ⇒ Object



95
96
97
98
99
100
101
102
103
104
105
106
# File 'lib/ieparser_extension.rb', line 95

def split_with_selector(element_to_find)
  element_hash = {}
  if has_a_selector?(element_to_find)
    selector = element_to_find.split(":")  
    element_hash.store(:element_name, selector[0].upcase)
    element_hash.store(:element_index, selector[1].to_i)
  else
    element_hash.store(:element_name, element_to_find.upcase)
    element_hash.store(:element_index, 0)
  end
  element_hash
end