xpgrep 0.1.0 → 0.2.0
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.
- data/History.txt +6 -0
- data/README.txt +2 -1
- data/Rakefile +0 -1
- data/TODO.txt +0 -2
- data/lib/xpgrep.rb +15 -3
- metadata +4 -4
data/History.txt
CHANGED
data/README.txt
CHANGED
@@ -21,7 +21,8 @@ grep(1) for XML, using XPath (or CSS selectors) instead of regex(3).
|
|
21
21
|
-h, --no-filename suppress printing filename for matches
|
22
22
|
-l, --files-with-matches only print filenames containing matches
|
23
23
|
-L, --files-without-match only print filenames containing no match
|
24
|
-
-e, --extract
|
24
|
+
-e, --extract <attr> extract the value of the given attribute
|
25
|
+
-t, --html parse file(s) as HTML
|
25
26
|
--help print this message and exit
|
26
27
|
|
27
28
|
== REQUIREMENTS:
|
data/Rakefile
CHANGED
data/TODO.txt
CHANGED
data/lib/xpgrep.rb
CHANGED
@@ -4,15 +4,21 @@ require 'hpricot'
|
|
4
4
|
|
5
5
|
module XPGrep
|
6
6
|
|
7
|
+
VERSION = '0.2.0'
|
8
|
+
|
7
9
|
def self.grep(expr, io)
|
8
|
-
h =
|
10
|
+
h = if CLI::Options.instance.parse_as_html
|
11
|
+
Hpricot(io)
|
12
|
+
else
|
13
|
+
Hpricot::XML(io)
|
14
|
+
end
|
9
15
|
h.search(expr)
|
10
16
|
end
|
11
17
|
|
12
18
|
|
13
19
|
module CLI
|
14
20
|
Options = Struct.new(:print_filename, :files_with_matches,
|
15
|
-
:files_without_match, :attribute)
|
21
|
+
:files_without_match, :attribute, :parse_as_html)
|
16
22
|
class Options
|
17
23
|
include Singleton
|
18
24
|
|
@@ -97,7 +103,13 @@ module XPGrep
|
|
97
103
|
"only print filenames containing no match") {
|
98
104
|
@options.files_without_match!
|
99
105
|
}
|
100
|
-
o.on('-e', '--extract
|
106
|
+
o.on('-e', '--extract <attr>',
|
107
|
+
'extract the value of the given attribute') {|attr|
|
108
|
+
@options[:attribute] = attr
|
109
|
+
}
|
110
|
+
o.on('-t', '--html', 'parse file(s) as HTML') {
|
111
|
+
@options.parse_as_html = true
|
112
|
+
}
|
101
113
|
o.on_tail('--help', "print this message and exit") { puts o; exit }
|
102
114
|
end.parse!(args)
|
103
115
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: xpgrep
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 23
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
-
-
|
8
|
+
- 2
|
9
9
|
- 0
|
10
|
-
version: 0.
|
10
|
+
version: 0.2.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Kevin R. Bullock
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2010-
|
18
|
+
date: 2010-10-13 00:00:00 -05:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|