Class: Rix::Command
- Inherits:
-
Object
show all
- Defined in:
- lib/rix/command.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
Instance Attribute Details
#files ⇒ Object
Returns the value of attribute files.
6
7
8
|
# File 'lib/rix/command.rb', line 6
def files
@files
end
|
#out ⇒ Object
Returns the value of attribute out.
5
6
7
|
# File 'lib/rix/command.rb', line 5
def out
@out
end
|
#xpath ⇒ Object
Returns the value of attribute xpath.
7
8
9
|
# File 'lib/rix/command.rb', line 7
def xpath
@xpath
end
|
Instance Method Details
#after(name, document) ⇒ Object
74
|
# File 'lib/rix/command.rb', line 74
def after(name, document); end
|
#after_all ⇒ Object
76
|
# File 'lib/rix/command.rb', line 76
def after_all; end
|
#before(name, document, nodes) ⇒ Object
64
|
# File 'lib/rix/command.rb', line 64
def before(name, document, nodes); end
|
#before_all ⇒ Object
62
|
# File 'lib/rix/command.rb', line 62
def before_all; end
|
#execute ⇒ Object
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
|
# File 'lib/rix/command.rb', line 17
def execute
@files = []
@value = ""
opts.parse!
@xpath = ARGV.shift.dup if ARGV.size > 0
@files = ARGV.uniq if ARGV.size > 0
raise "Missing XPath expression" if @xpath.nil? or @xpath.empty?
before_all
@files.each do |pattern|
Dir[pattern].each do |path|
File.open(path, 'r') do |file|
on_source(file, path)
end
end
end
after_all
end
|
#help ⇒ Object
13
14
15
|
# File 'lib/rix/command.rb', line 13
def help
opts.help
end
|
#on_attribute(attribute) ⇒ Object
70
|
# File 'lib/rix/command.rb', line 70
def on_attribute(attribute); end
|
#on_document(document, name) ⇒ Object
50
51
52
53
54
55
56
57
58
59
60
|
# File 'lib/rix/command.rb', line 50
def on_document(document, name)
nodes = XPath.match(document, @xpath)
before(name, document, nodes)
nodes.each do |node|
on_node(node)
on_element(node) if node.is_a? Element
on_attribute(node) if node.is_a? Attribute
on_text(node) if node.is_a? Text
end
after(name, document)
end
|
#on_element(element) ⇒ Object
68
|
# File 'lib/rix/command.rb', line 68
def on_element(element); end
|
#on_node(node) ⇒ Object
66
|
# File 'lib/rix/command.rb', line 66
def on_node(node); end
|
#on_source(source, name) ⇒ Object
45
46
47
48
|
# File 'lib/rix/command.rb', line 45
def on_source(source, name)
document = Document.new(source, :ignore_whitespace_nodes => :all, :attribute_quote => :quote)
on_document(document, name)
end
|
#on_text(text) ⇒ Object
72
|
# File 'lib/rix/command.rb', line 72
def on_text(text); end
|
#opts ⇒ Object
9
10
11
|
# File 'lib/rix/command.rb', line 9
def opts
OptionParser.new
end
|