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.
Files changed (6) hide show
  1. data/History.txt +6 -0
  2. data/README.txt +2 -1
  3. data/Rakefile +0 -1
  4. data/TODO.txt +0 -2
  5. data/lib/xpgrep.rb +15 -3
  6. metadata +4 -4
@@ -1,3 +1,9 @@
1
+ === 0.2.0 / 2010-10-13
2
+
3
+ * 1 major enhancement
4
+
5
+ * Add -t/--html option to parse files as HTML instead of XML
6
+
1
7
  === 0.1.0 / 2010-07-14
2
8
 
3
9
  * 1 major enhancement
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 ATTR
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
@@ -4,7 +4,6 @@ require 'rubygems'
4
4
  require 'hoe'
5
5
 
6
6
  Hoe.spec 'xpgrep' do
7
- self.version = '0.1.0'
8
7
  developer('Kevin R. Bullock', 'kbullock@ringworld.org')
9
8
  self.rubyforge_name = 'handtools'
10
9
 
data/TODO.txt CHANGED
@@ -1,5 +1,3 @@
1
- * Add HTML switch (to use Hpricot() instead of Hpricot::XML())
2
-
3
1
  * Add first-line output switch (for elements with huge content)
4
2
 
5
3
  * Also, add start-tag output switch (likewise)
@@ -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 = Hpricot::XML(io)
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 ATTR') {|attr| @options[:attribute] = attr }
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: 27
4
+ hash: 23
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
- - 1
8
+ - 2
9
9
  - 0
10
- version: 0.1.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-07-14 00:00:00 -05:00
18
+ date: 2010-10-13 00:00:00 -05:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency