watir_crawler 0.0.1 → 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -21,12 +21,6 @@ class CrawlerExample < WatirCrawler::Base
21
21
  end
22
22
  end
23
23
 
24
- def goto_login
25
- browser_session do
26
- goto 'https://myaccount.alagasco.com/ccsuces/public/frameset_top_html.jsp'
27
- end
28
- end
29
-
30
24
  def google_news
31
25
  browser_session do
32
26
  goto 'http://news.google.com/'
@@ -83,9 +83,8 @@ module WatirCrawler
83
83
  browser.execute_script(script)
84
84
  end
85
85
 
86
- # #####################################################################################################
87
-
88
86
  # --------------------------------------------------------------------------------------------------------------------
87
+
89
88
  def pull *args, &block
90
89
  opts, xpaths = args.flatten.partition{|a| a.is_a?(Symbol) }
91
90
  opt_mode = opts.delete(:exist?) || opts.delete(:present?) || :present? # default is :present?
@@ -98,11 +97,19 @@ module WatirCrawler
98
97
  nodes_for(xpath) # get all elements
99
98
  end.flatten.select do |node|
100
99
  node.send(opt_mode) # select elements by mode
100
+ end.map do |node|
101
+ subtype = node.to_subtype
102
+ class << subtype
103
+ attr_accessor :node_xpath
104
+ end
105
+
106
+ subtype.node_xpath = node.node_xpath
107
+ subtype
101
108
  end
102
109
 
103
110
  # flash result nodes
104
111
  elements = elements.take(1) if opt_first
105
- elements.each{|node| node.flash unless node.is_a?(Watir::Frame) }
112
+ elements.each{|node| node.flash unless node.is_a?(Watir::Frame) || node.is_a?(Watir::IFrame) }
106
113
 
107
114
  first_element = elements.first
108
115
 
@@ -111,11 +118,7 @@ module WatirCrawler
111
118
  nodes_path << first_element.node_xpath
112
119
  yield
113
120
  else
114
- if opt_first
115
- first_element && first_element.to_subtype
116
- else
117
- elements.map{|element| element.to_subtype }
118
- end
121
+ opt_first ? first_element : elements
119
122
  end
120
123
  rescue Selenium::WebDriver::Error::StaleElementReferenceError,
121
124
  Selenium::WebDriver::Error::ObsoleteElementError
@@ -186,12 +189,15 @@ module WatirCrawler
186
189
  elements = elements.to_a if elements.is_a? Watir::ElementCollection
187
190
  elements = [elements].flatten
188
191
 
192
+ has_multiple_elements = elements.size > 1
193
+
189
194
  elements.map.with_index do |element, index|
190
195
  class << element
191
196
  attr_accessor :node_xpath
192
197
  end
193
198
 
194
- element.node_xpath = xpath + "[#{index + 1}]"
199
+ element.node_xpath = xpath
200
+ element.node_xpath += "[#{index + 1}]" if has_multiple_elements
195
201
  element
196
202
  end
197
203
  end
@@ -1,3 +1,3 @@
1
1
  module WatirCrawler
2
- VERSION = '0.0.1'
2
+ VERSION = '0.0.2'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: watir_crawler
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-01-21 00:00:00.000000000 Z
12
+ date: 2014-01-22 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: nestegg
@@ -147,7 +147,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
147
147
  version: '0'
148
148
  segments:
149
149
  - 0
150
- hash: -715382381
150
+ hash: -79542161
151
151
  required_rubygems_version: !ruby/object:Gem::Requirement
152
152
  none: false
153
153
  requirements:
@@ -156,7 +156,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
156
156
  version: '0'
157
157
  segments:
158
158
  - 0
159
- hash: -715382381
159
+ hash: -79542161
160
160
  requirements: []
161
161
  rubyforge_project:
162
162
  rubygems_version: 1.8.25