iegrip 0.0.4
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.
- checksums.yaml +7 -0
- data/.gitignore +14 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +31 -0
- data/Rakefile +2 -0
- data/iegrip-0.0.2.gem +0 -0
- data/iegrip.gemspec +23 -0
- data/lib/iegrip/GripWrapper.rb +68 -0
- data/lib/iegrip/version.rb +3 -0
- data/lib/iegrip.rb +541 -0
- metadata +82 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 4c45c0f0882cc76475e1140bc1ee21e6a3ba6d66
|
4
|
+
data.tar.gz: 451d53a837b9b8611e494d9bb0e2e0c808a5e6ca
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 40c1f957bb348752a61130da1fb2c88c10e45a2422a1a0dfc63f73e066feb742f3a89ce54ebd6bb4e256262ea0393a2526716b555ce1bdd4dbab547e2d19bde9
|
7
|
+
data.tar.gz: e67222c69f2785c7b83ed7e261ed3516fbe0b8d700ed35965b2382735daa4e97a474d2a3153e6aeeaf5303568d0603ba20c89ead072b904479722568636699a6
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 yac4423
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
# Iegrip
|
2
|
+
|
3
|
+
TODO: Write a gem description
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'iegrip'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install iegrip
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
TODO: Write usage instructions here
|
24
|
+
|
25
|
+
## Contributing
|
26
|
+
|
27
|
+
1. Fork it ( https://github.com/[my-github-username]/iegrip/fork )
|
28
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
29
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
30
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
31
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
data/iegrip-0.0.2.gem
ADDED
Binary file
|
data/iegrip.gemspec
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'iegrip/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "iegrip"
|
8
|
+
spec.version = IEgrip::VERSION
|
9
|
+
spec.authors = ["yac4423"]
|
10
|
+
spec.email = ["iegrip@tech-notes.dyndns.org"]
|
11
|
+
spec.summary = %q{Control Internet Explorer from Ruby script.}
|
12
|
+
spec.description = %q{Control Internet Explorer from Ruby script.}
|
13
|
+
spec.homepage = "https://github.com/yac4423/iegrip"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.6"
|
22
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
23
|
+
end
|
@@ -0,0 +1,68 @@
|
|
1
|
+
module IEgrip
|
2
|
+
class GripWrapper
|
3
|
+
def initialize(raw_object, ie_obj)
|
4
|
+
if raw_object.methods.include?("raw")
|
5
|
+
@raw_object = raw_object.raw
|
6
|
+
else
|
7
|
+
@raw_object = raw_object
|
8
|
+
end
|
9
|
+
@ie_obj = ie_obj
|
10
|
+
end
|
11
|
+
|
12
|
+
def raw
|
13
|
+
@raw_object
|
14
|
+
end
|
15
|
+
|
16
|
+
def inspect()
|
17
|
+
"<#{self.class}>"
|
18
|
+
end
|
19
|
+
|
20
|
+
def ole_methodNames
|
21
|
+
list = []
|
22
|
+
@raw_object.ole_methods.each {|ole_method|
|
23
|
+
list.push ole_method.name
|
24
|
+
}
|
25
|
+
list
|
26
|
+
end
|
27
|
+
|
28
|
+
private
|
29
|
+
|
30
|
+
OLE_METHODS = [:Type, :Initialize]
|
31
|
+
def method_missing(m_id, *params)
|
32
|
+
unless OLE_METHODS.include?(m_id)
|
33
|
+
missing_method_name = m_id.to_s.downcase
|
34
|
+
methods.each {|method|
|
35
|
+
if method.to_s.downcase == missing_method_name
|
36
|
+
return send(method, *params)
|
37
|
+
end
|
38
|
+
}
|
39
|
+
end
|
40
|
+
# Undefined Method is throwed to raw_object
|
41
|
+
begin
|
42
|
+
@raw_object.send(m_id, *params)
|
43
|
+
rescue
|
44
|
+
raise $!,$!.message, caller
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
def toRaw(target_obj)
|
49
|
+
target_obj.respond_to?("raw") ? target_obj.raw : target_obj
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
class FileSystemObject
|
54
|
+
include Singleton
|
55
|
+
def initialize
|
56
|
+
@body = WIN32OLE.new('Scripting.FileSystemObject')
|
57
|
+
end
|
58
|
+
|
59
|
+
def fullpath(filename)
|
60
|
+
@body.getAbsolutePathName(filename)
|
61
|
+
end
|
62
|
+
|
63
|
+
def GetFileVersion(fullpath)
|
64
|
+
@body.GetFileVersion(fullpath)
|
65
|
+
end
|
66
|
+
|
67
|
+
end
|
68
|
+
end
|
data/lib/iegrip.rb
ADDED
@@ -0,0 +1,541 @@
|
|
1
|
+
#!ruby -Ks
|
2
|
+
|
3
|
+
# IEGrip Ver.0.00 2014/10/06
|
4
|
+
# Copyright (C) 2014 Yac <iegrip@tech-notes.dyndns.org>
|
5
|
+
# This software is released under the MIT License, see LICENSE.txt.
|
6
|
+
require 'win32ole'
|
7
|
+
require 'win32api'
|
8
|
+
require 'singleton'
|
9
|
+
require "iegrip/version"
|
10
|
+
require 'iegrip/GripWrapper'
|
11
|
+
|
12
|
+
module IEgrip
|
13
|
+
# ========================
|
14
|
+
# IE Application
|
15
|
+
# ========================
|
16
|
+
class IE < GripWrapper
|
17
|
+
def initialize()
|
18
|
+
@raw_object = WIN32OLE.new("InternetExplorer.Application")
|
19
|
+
@raw_object.visible = true
|
20
|
+
fs = FileSystemObject.instance
|
21
|
+
ver = fs.GetFileVersion(@raw_object.FullName)
|
22
|
+
@majorVersion = ver.split(/\./)[0].to_i
|
23
|
+
@urlDownloadToFile = Win32API.new('urlmon', 'URLDownloadToFileA', %w(l p p l l), 'l')
|
24
|
+
end
|
25
|
+
|
26
|
+
def version
|
27
|
+
@majorVersion
|
28
|
+
end
|
29
|
+
|
30
|
+
def document()
|
31
|
+
doc = Document.new(@raw_object.Document, self)
|
32
|
+
end
|
33
|
+
|
34
|
+
def navigate(url)
|
35
|
+
@raw_object.navigate(url)
|
36
|
+
sleep 0.5
|
37
|
+
wait_stable()
|
38
|
+
end
|
39
|
+
|
40
|
+
COMPLETE_STATE = 4
|
41
|
+
def wait_stable()
|
42
|
+
while @raw_object.Busy == true
|
43
|
+
sleep 0.5
|
44
|
+
end
|
45
|
+
loop do
|
46
|
+
break if @raw_object.ReadyState == COMPLETE_STATE
|
47
|
+
sleep 0.5
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
def export(href, filename)
|
52
|
+
@urlDownloadToFile.call(0, href, filename, 0, 0)
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
# ========================
|
57
|
+
# Node
|
58
|
+
# ========================
|
59
|
+
class Node < GripWrapper
|
60
|
+
NODETYPE_DIC = {
|
61
|
+
1 => :ELEMENT_NODE,
|
62
|
+
2 => :ATTRIBUTE_NODE,
|
63
|
+
3 => :TEXT_NODE,
|
64
|
+
4 => :CDATA_SECTION_NODE,
|
65
|
+
5 => :ENTITY_REFERENCE_NODE,
|
66
|
+
6 => :ENTITY_NODE,
|
67
|
+
7 => :PROCESSING_INSTRUCTION_NODE,
|
68
|
+
8 => :COMMENT_NODE,
|
69
|
+
9 => :DOCUMENT_NODE,
|
70
|
+
10 => :DOCUMENT_TYPE_NODE,
|
71
|
+
11 => :DOCUMENT_FRAGMENT_NODE,
|
72
|
+
12 => :NOTATION_NODE,
|
73
|
+
}
|
74
|
+
def tagName
|
75
|
+
case self.nodeType
|
76
|
+
when 3
|
77
|
+
@raw_object.nodeName
|
78
|
+
else
|
79
|
+
@raw_object.tagName.downcase
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
def nodeName
|
84
|
+
@raw_object.nodeName
|
85
|
+
end
|
86
|
+
|
87
|
+
def nodeTypeName
|
88
|
+
nodetype = @raw_object.nodetype
|
89
|
+
NODETYPE_DIC[nodetype] || :UNKNOWN
|
90
|
+
end
|
91
|
+
|
92
|
+
def inspect
|
93
|
+
"<#{self.class}, Name:#{self.nodeName}>"
|
94
|
+
end
|
95
|
+
|
96
|
+
def childNodes
|
97
|
+
raw_childNodes = @raw_object.childNodes
|
98
|
+
raw_childNodes ? NodeList.new(raw_childNodes, @ie_obj) : nil
|
99
|
+
end
|
100
|
+
|
101
|
+
def parentNode
|
102
|
+
raw_element = @raw_object.parentNode()
|
103
|
+
raw_element ? TagElement.new(raw_element, @ie_obj) : nil
|
104
|
+
end
|
105
|
+
|
106
|
+
def previousSibling
|
107
|
+
raw_node = @raw_object.previousSibling()
|
108
|
+
raw_node ? Node.new(raw_node, @ie_obj) : nil
|
109
|
+
end
|
110
|
+
|
111
|
+
def nextSibling
|
112
|
+
raw_node = @raw_object.nextSibling()
|
113
|
+
raw_node ? Node.new(raw_node, @ie_obj) : nil
|
114
|
+
end
|
115
|
+
|
116
|
+
def firstChild
|
117
|
+
raw_node = @raw_object.firstChild()
|
118
|
+
raw_node ? Node.new(raw_node, @ie_obj) : nil
|
119
|
+
end
|
120
|
+
|
121
|
+
def lastChild
|
122
|
+
raw_node = @raw_object.lastChild()
|
123
|
+
raw_node ? Node.new(raw_node, @ie_obj) : nil
|
124
|
+
end
|
125
|
+
|
126
|
+
def hasChildNodes()
|
127
|
+
#@raw_object.hasChildNodes() # This method return WIN32OLE object. not boolean
|
128
|
+
@raw_object.childNodes.length > 0
|
129
|
+
end
|
130
|
+
|
131
|
+
def contains(node)
|
132
|
+
@raw_object.contains(toRaw(node))
|
133
|
+
end
|
134
|
+
|
135
|
+
def isEqualNode(node)
|
136
|
+
@raw_object.isEqualNode(toRaw(node))
|
137
|
+
end
|
138
|
+
|
139
|
+
def getElementById(tag_id)
|
140
|
+
raw_element = @raw_object.getElementById(tag_id)
|
141
|
+
raw_element ? TagElement.new(raw_element, @ie_obj) : nil
|
142
|
+
end
|
143
|
+
|
144
|
+
def getElementsByName(name)
|
145
|
+
raw_col = @raw_object.getElementsByName(name)
|
146
|
+
raw_col ? TagElementCollection.new(raw_col, @ie_obj) : nil
|
147
|
+
end
|
148
|
+
|
149
|
+
def getElementsByTagName(tag_name)
|
150
|
+
raw_col = @raw_object.getElementsByTagName(tag_name)
|
151
|
+
raw_col ? TagElementCollection.new(raw_col, @ie_obj) : nil
|
152
|
+
end
|
153
|
+
alias tags getElementsByTagName
|
154
|
+
|
155
|
+
def getStructure(level=0)
|
156
|
+
structure = []
|
157
|
+
self.childNodes.each {|subnode|
|
158
|
+
next if (subnode.nodeType == 3) or (subnode.nodeType == 8)
|
159
|
+
if subnode.hasChildNodes()
|
160
|
+
sub_struct = subnode.getStructure(level+1)
|
161
|
+
if sub_struct.size > 0
|
162
|
+
structure.push (" " * level) + "<#{subnode.tagName}>"
|
163
|
+
structure += sub_struct
|
164
|
+
structure.push (" " * level) + "</#{subnode.tagName}>"
|
165
|
+
else
|
166
|
+
structure.push (" " * level) + "<#{subnode.tagName}/>"
|
167
|
+
end
|
168
|
+
else
|
169
|
+
structure.push (" " * level) + "<#{subnode.tagName}/>"
|
170
|
+
end
|
171
|
+
}
|
172
|
+
return structure
|
173
|
+
end
|
174
|
+
end
|
175
|
+
|
176
|
+
# ========================
|
177
|
+
# IE.Document
|
178
|
+
# ========================
|
179
|
+
class Document < Node
|
180
|
+
def frames(index=nil)
|
181
|
+
if index
|
182
|
+
return(nil) if index >= @raw_object.Frames.length
|
183
|
+
Frames.new(@raw_object.frames, @ie_obj)[index]
|
184
|
+
else
|
185
|
+
Frames.new(@raw_object.frames, @ie_obj)
|
186
|
+
end
|
187
|
+
end
|
188
|
+
|
189
|
+
def head()
|
190
|
+
raw_head = @raw_object.head
|
191
|
+
raw_head ? TagElement.new(raw_head, @ie_obj) : nil
|
192
|
+
end
|
193
|
+
|
194
|
+
def body()
|
195
|
+
#raw_body = @raw_object.getElementsByTagName("BODY")
|
196
|
+
#raw_body ? TagElementCollection.new(raw_body, @ie_obj)[0] : nil
|
197
|
+
TagElement.new(@raw_object.body, @ie_obj)
|
198
|
+
end
|
199
|
+
|
200
|
+
def all
|
201
|
+
raw_all = @raw_object.all
|
202
|
+
raw_all ? TagElementCollection.new(raw_all, @ie_obj) : nil
|
203
|
+
end
|
204
|
+
|
205
|
+
|
206
|
+
def documentElement
|
207
|
+
raw_element = @raw_object.documentElement()
|
208
|
+
raw_element ? TagElement.new(raw_element, @ie_obj) : nil
|
209
|
+
end
|
210
|
+
|
211
|
+
def createElement(tag_name)
|
212
|
+
raw_element = @raw_object.createElement(tag_name)
|
213
|
+
TagElement.new(raw_element, @ie_obj)
|
214
|
+
end
|
215
|
+
|
216
|
+
def createAttribute(attr_name)
|
217
|
+
raw_attr = @raw_object.createAttribute(attr_name);
|
218
|
+
Attr.new(raw_attr, @ie_obj)
|
219
|
+
end
|
220
|
+
|
221
|
+
end
|
222
|
+
|
223
|
+
# ========================
|
224
|
+
# TAG Element
|
225
|
+
# ========================
|
226
|
+
class TagElement < Node
|
227
|
+
def tagname
|
228
|
+
@raw_object.tagName.downcase
|
229
|
+
end
|
230
|
+
|
231
|
+
def text=(set_text)
|
232
|
+
case tagName
|
233
|
+
when "SELECT"
|
234
|
+
option_list = tags("OPTION")
|
235
|
+
option_list.each {|option_element|
|
236
|
+
if option_element.innerText == set_text
|
237
|
+
option_element.selected = true
|
238
|
+
break
|
239
|
+
end
|
240
|
+
}
|
241
|
+
else
|
242
|
+
@raw_object.value = set_text
|
243
|
+
end
|
244
|
+
end
|
245
|
+
|
246
|
+
def inspect()
|
247
|
+
case tagName
|
248
|
+
when "SELECT"
|
249
|
+
innerHTML = replace_cr_code(self.innerHTML)
|
250
|
+
"<#{self.class}, TAG:#{tagName}, [#{self.innerHTML}]"
|
251
|
+
when "INPUT", "IMG", "A"
|
252
|
+
outerHTML = replace_cr_code(self.outerHTML)
|
253
|
+
"<#{self.class}, TAG:#{tagName}, [#{self.outerHTML}]"
|
254
|
+
when "TR", "TD"
|
255
|
+
innerText = replace_cr_code(self.innerText)
|
256
|
+
"<#{self.class}, TAG:#{tagName}, [#{innerText}]"
|
257
|
+
else
|
258
|
+
"<#{self.class}, TAG:#{tagName}>"
|
259
|
+
end
|
260
|
+
end
|
261
|
+
|
262
|
+
def to_s
|
263
|
+
@raw_object.value
|
264
|
+
end
|
265
|
+
|
266
|
+
def click
|
267
|
+
if @ie_obj.version >= 10
|
268
|
+
case self.tagname.downcase
|
269
|
+
when "a"
|
270
|
+
href = self.href
|
271
|
+
@ie_obj.navigate(href)
|
272
|
+
when "input"
|
273
|
+
if self.Type.downcase == "submit"
|
274
|
+
puts "**** Submit Type is detected."
|
275
|
+
parent_form = self.getParentForm()
|
276
|
+
if parent_form
|
277
|
+
puts "parent_form = #{parent_form.outerHTML}"
|
278
|
+
ret_val = parent_form.submit()
|
279
|
+
puts "parent_form.submit() submit is called. ret_val = #{ret_val.inspect}"
|
280
|
+
sleep 1
|
281
|
+
parent_form.raw.submit()
|
282
|
+
parent_form.fireEvent("onSubmit")
|
283
|
+
parent_form.fireEvent("onClick")
|
284
|
+
else
|
285
|
+
puts "parent_form not detected."
|
286
|
+
end
|
287
|
+
end
|
288
|
+
when "button"
|
289
|
+
@raw_object.fireEvent("onClick")
|
290
|
+
else
|
291
|
+
@raw_object.click
|
292
|
+
end
|
293
|
+
else
|
294
|
+
@raw_object.click
|
295
|
+
end
|
296
|
+
@ie_obj.wait_stable()
|
297
|
+
end
|
298
|
+
|
299
|
+
def getElementsByTagName(tag_name)
|
300
|
+
raw_collection = @raw_object.getElementsByTagName(tag_name)
|
301
|
+
raw_collection ? TagElementCollection.new(raw_collection, @ie_obj) : nil
|
302
|
+
end
|
303
|
+
alias tags getElementsByTagName
|
304
|
+
|
305
|
+
def all
|
306
|
+
TagElementCollection.new(@raw_object.all, @ie_obj)
|
307
|
+
end
|
308
|
+
|
309
|
+
def parentElement
|
310
|
+
raw_parent = @raw_object.parentElement
|
311
|
+
raw_parent ? TagElement.new(raw_parent, @ie_obj) : nil
|
312
|
+
end
|
313
|
+
|
314
|
+
def getParentForm()
|
315
|
+
puts "getParentForm() is called."
|
316
|
+
parent_tag = self.parentElement
|
317
|
+
loop do
|
318
|
+
puts "parent_tag = #{parent_tag.inspect}"
|
319
|
+
if parent_tag == nil
|
320
|
+
return nil
|
321
|
+
elsif parent_tag.tagName == "form"
|
322
|
+
return parent_tag
|
323
|
+
else
|
324
|
+
parent_tag = parent_tag.parentElement
|
325
|
+
end
|
326
|
+
end
|
327
|
+
end
|
328
|
+
|
329
|
+
def export(filename)
|
330
|
+
case self.tagName.downcase
|
331
|
+
when "img"
|
332
|
+
@ie_obj.export(self.src, filename)
|
333
|
+
when "a"
|
334
|
+
@ie_obj.export(self.href, filename)
|
335
|
+
else
|
336
|
+
raise "export() is not support."
|
337
|
+
end
|
338
|
+
end
|
339
|
+
|
340
|
+
def setAttributeNode(attribute)
|
341
|
+
@raw_object.setAttributeNode(toRaw(attribute));
|
342
|
+
end
|
343
|
+
|
344
|
+
def getAttribute(attr_name)
|
345
|
+
@raw_object.getAttribute(attr_name)
|
346
|
+
end
|
347
|
+
|
348
|
+
def getAttributeNode(attr_name)
|
349
|
+
raw_attr = @raw_object.getAttributeNode(attr_name)
|
350
|
+
raw_attr ? Attr.new(raw_attr, @ie_obj) : nil
|
351
|
+
end
|
352
|
+
|
353
|
+
def removeAttribute(attr_name)
|
354
|
+
@raw_object.removeAttribute(attr_name)
|
355
|
+
end
|
356
|
+
|
357
|
+
def removeAttributeNode( attr )
|
358
|
+
raw_attr = @raw_object.removeAttributeNode( toRaw(attr) )
|
359
|
+
raw_attr ? Attr.new(raw_attr, @ie_obj) : nil
|
360
|
+
end
|
361
|
+
|
362
|
+
private
|
363
|
+
|
364
|
+
def replace_cr_code(text)
|
365
|
+
replcae_text = text.gsub(/\r/, '\r')
|
366
|
+
replcae_text.gsub!(/\n/, '\n')
|
367
|
+
return replcae_text
|
368
|
+
end
|
369
|
+
end
|
370
|
+
|
371
|
+
# ========================
|
372
|
+
# TAG Element Collection
|
373
|
+
# ========================
|
374
|
+
class TagElementCollection < GripWrapper
|
375
|
+
def [](index)
|
376
|
+
return(nil) if index >= @raw_object.length
|
377
|
+
TagElement.new(@raw_object.item(index), @ie_obj)
|
378
|
+
end
|
379
|
+
|
380
|
+
def size
|
381
|
+
@raw_object.length
|
382
|
+
end
|
383
|
+
|
384
|
+
def each
|
385
|
+
@raw_object.each {|tag_element|
|
386
|
+
yield TagElement.new(tag_element, @ie_obj)
|
387
|
+
}
|
388
|
+
end
|
389
|
+
|
390
|
+
def getTagsByTitle(target_str)
|
391
|
+
get_tags_by_key(target_str, "VALUE")
|
392
|
+
end
|
393
|
+
def getTagsByValue(target_str)
|
394
|
+
get_tags_by_key(target_str, "VALUE")
|
395
|
+
end
|
396
|
+
def getTagsByText(target_str)
|
397
|
+
get_tags_by_key(target_str, "INNERTEXT")
|
398
|
+
end
|
399
|
+
def getTagsByName(target_str)
|
400
|
+
get_tags_by_key(target_str, "NAME")
|
401
|
+
end
|
402
|
+
|
403
|
+
def getTagByTitle(target_str)
|
404
|
+
taglist = get_tags_by_key(target_str, "VALUE")
|
405
|
+
taglist ? taglist[0]: nil
|
406
|
+
end
|
407
|
+
def getTagByValue(target_str)
|
408
|
+
taglist = get_tags_by_key(target_str, "VALUE")
|
409
|
+
taglist ? taglist[0]: nil
|
410
|
+
end
|
411
|
+
def getTagByText(target_str)
|
412
|
+
taglist = get_tags_by_key(target_str, "INNERTEXT")
|
413
|
+
taglist ? taglist[0]: nil
|
414
|
+
end
|
415
|
+
def getTagByName(target_str)
|
416
|
+
taglist = get_tags_by_key(target_str, "NAME")
|
417
|
+
taglist ? taglist[0]: nil
|
418
|
+
end
|
419
|
+
def getTagByID(target_id)
|
420
|
+
taglist = get_tags_by_key(target_id, "ID")
|
421
|
+
taglist ? taglist[0]: nil
|
422
|
+
end
|
423
|
+
|
424
|
+
def inspect()
|
425
|
+
tagname_list = []
|
426
|
+
self.each {|tag_element|
|
427
|
+
tagname_list.push "<#{tag_element.tagName}>"
|
428
|
+
}
|
429
|
+
if tagname_list.size > 3
|
430
|
+
"<#{self.class}: [#{tagname_list[0,3].join(', ')},...]"
|
431
|
+
else
|
432
|
+
"<#{self.class}: [#{tagname_list.join(', ')}]>"
|
433
|
+
end
|
434
|
+
end
|
435
|
+
|
436
|
+
private
|
437
|
+
|
438
|
+
def get_tags_by_key(target_str, key_type)
|
439
|
+
tag_list = []
|
440
|
+
@raw_object.each {|tag_element|
|
441
|
+
case key_type
|
442
|
+
when "INNERTEXT"
|
443
|
+
key_string = tag_element.innerText
|
444
|
+
when "VALUE"
|
445
|
+
key_string = tag_element.value
|
446
|
+
when "NAME"
|
447
|
+
key_string = tag_element.name
|
448
|
+
when "ID"
|
449
|
+
key_string = tag_element.ID
|
450
|
+
else
|
451
|
+
return nil
|
452
|
+
end
|
453
|
+
if key_string == target_str
|
454
|
+
tag_list.push TagElement.new(tag_element, @ie_obj)
|
455
|
+
end
|
456
|
+
}
|
457
|
+
case tag_list.size
|
458
|
+
when 0
|
459
|
+
return nil
|
460
|
+
else
|
461
|
+
return tag_list
|
462
|
+
end
|
463
|
+
end
|
464
|
+
|
465
|
+
end
|
466
|
+
|
467
|
+
|
468
|
+
|
469
|
+
# ========================
|
470
|
+
# IE.Document.Frames
|
471
|
+
# ========================
|
472
|
+
class Frames < GripWrapper
|
473
|
+
def [](index)
|
474
|
+
return(nil) if index >= @raw_object.length
|
475
|
+
Frame.new(@raw_object.item(index), @ie_obj)
|
476
|
+
end
|
477
|
+
|
478
|
+
def size
|
479
|
+
@raw_object.length
|
480
|
+
end
|
481
|
+
|
482
|
+
def each
|
483
|
+
index = 0
|
484
|
+
while index < @raw_object.length
|
485
|
+
raw_frame = @raw_object.item(index)
|
486
|
+
yield Frame.new(raw_frame, @ie_obj)
|
487
|
+
index += 1
|
488
|
+
end
|
489
|
+
end
|
490
|
+
end
|
491
|
+
|
492
|
+
# ========================
|
493
|
+
# IE.Document.Frames.item(n)
|
494
|
+
# ========================
|
495
|
+
class Frame < GripWrapper
|
496
|
+
def document
|
497
|
+
Document.new(@raw_object.document, @ie_obj)
|
498
|
+
end
|
499
|
+
end
|
500
|
+
|
501
|
+
# ========================
|
502
|
+
# NodeList
|
503
|
+
# ========================
|
504
|
+
class NodeList < GripWrapper
|
505
|
+
def [](index)
|
506
|
+
return(nil) if index >= @raw_object.length
|
507
|
+
Node.new(@raw_object.item(index), @ie_obj)
|
508
|
+
end
|
509
|
+
|
510
|
+
def size
|
511
|
+
@raw_object.length
|
512
|
+
end
|
513
|
+
|
514
|
+
def each
|
515
|
+
index = 0
|
516
|
+
loop do
|
517
|
+
break if index >= @raw_object.length
|
518
|
+
raw_node = @raw_object.item(index)
|
519
|
+
yield Node.new(raw_node, @ie_obj)
|
520
|
+
index += 1
|
521
|
+
end
|
522
|
+
end
|
523
|
+
end
|
524
|
+
|
525
|
+
|
526
|
+
class Attr < GripWrapper
|
527
|
+
def value=(value_str)
|
528
|
+
@raw_object.value = value_str
|
529
|
+
end
|
530
|
+
def value
|
531
|
+
@raw_object.value
|
532
|
+
end
|
533
|
+
|
534
|
+
def ownerElement()
|
535
|
+
TagElement.new(@raw_object.ownerElement, @ie_obj)
|
536
|
+
end
|
537
|
+
end
|
538
|
+
end
|
539
|
+
|
540
|
+
|
541
|
+
|
metadata
ADDED
@@ -0,0 +1,82 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: iegrip
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.4
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- yac4423
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-10-12 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.6'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.6'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ~>
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ~>
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
description: Control Internet Explorer from Ruby script.
|
42
|
+
email:
|
43
|
+
- iegrip@tech-notes.dyndns.org
|
44
|
+
executables: []
|
45
|
+
extensions: []
|
46
|
+
extra_rdoc_files: []
|
47
|
+
files:
|
48
|
+
- .gitignore
|
49
|
+
- Gemfile
|
50
|
+
- LICENSE.txt
|
51
|
+
- README.md
|
52
|
+
- Rakefile
|
53
|
+
- iegrip-0.0.2.gem
|
54
|
+
- iegrip.gemspec
|
55
|
+
- lib/iegrip.rb
|
56
|
+
- lib/iegrip/GripWrapper.rb
|
57
|
+
- lib/iegrip/version.rb
|
58
|
+
homepage: https://github.com/yac4423/iegrip
|
59
|
+
licenses:
|
60
|
+
- MIT
|
61
|
+
metadata: {}
|
62
|
+
post_install_message:
|
63
|
+
rdoc_options: []
|
64
|
+
require_paths:
|
65
|
+
- lib
|
66
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
67
|
+
requirements:
|
68
|
+
- - '>='
|
69
|
+
- !ruby/object:Gem::Version
|
70
|
+
version: '0'
|
71
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - '>='
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
requirements: []
|
77
|
+
rubyforge_project:
|
78
|
+
rubygems_version: 2.0.14
|
79
|
+
signing_key:
|
80
|
+
specification_version: 4
|
81
|
+
summary: Control Internet Explorer from Ruby script.
|
82
|
+
test_files: []
|