cudan 0.0.4 → 0.0.5

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/CHANGES CHANGED
@@ -1,3 +1,15 @@
1
+ = 0.0.5
2
+ * 2011/01/13
3
+ * change some options.
4
+
5
+ = 0.0.4
6
+ * 2011/01/12
7
+ * fix bug in xpath query.
8
+
9
+ = 0.0.3
10
+ * 2011/01/12
11
+ * update document.
12
+
1
13
  = 0.0.2
2
14
  * 2011/01/12
3
15
  * add dependancy on Nokogiri
@@ -4,5 +4,5 @@ module Cudan
4
4
  require 'cudan/regexp_cudan'
5
5
  require 'cudan/xpath_cudan'
6
6
  require 'cudan/main'
7
- VERSION="0.0.4"
7
+ VERSION="0.0.5"
8
8
  end
@@ -37,6 +37,7 @@ module Cudan
37
37
  end
38
38
  end
39
39
  def execute query, expect, url, method=GET, body=nil
40
+ @query = query
40
41
  fetch(url, method, body)
41
42
  @query_result = do_query(query)
42
43
  r = do_expect(expect)
@@ -48,6 +49,7 @@ module Cudan
48
49
  end
49
50
  def do_message
50
51
  Logger.log 'failure:'
52
+ Logger.log "query: #{@query}"
51
53
  Logger.log @query_result.gsub(/^(.*)$/){|r| "\t" + r}
52
54
  end
53
55
  def do_query query
@@ -8,6 +8,9 @@ class Cudan::Main
8
8
  exit
9
9
  end
10
10
  opts.on('-q QUERY', '--query QUERY', 'query') do |q|
11
+ if q==''
12
+ q = '/.*'
13
+ end
11
14
  @query = q
12
15
  end
13
16
  opts.on('-e EXPECT_STRING', '--expects EXPECT_STRING', 'expect string') do |ex|
@@ -19,6 +22,18 @@ class Cudan::Main
19
22
  opts.on('--show-body', 'show body') do |b|
20
23
  @showbody = b
21
24
  end
25
+ @mode = :css
26
+ opts.on('-m MODE', '--mode MODE', 'query mode. [regexp|xpath|css].', [:regexp, :xpath, :css]) do |m|
27
+ @mode = m
28
+ end
29
+ opts.on('-x QUERY', 'alias for "-q query --mode=xpath"') do |q|
30
+ @mode = :xpath
31
+ @query = q
32
+ end
33
+ opts.on('-r QUERY', 'alias for "-q query --mode=regexp"') do |q|
34
+ @mode = :regexp
35
+ @query = q
36
+ end
22
37
  opts.version = Cudan::VERSION
23
38
  opts.parse!(ARGV)
24
39
  @url = ARGV[0]
@@ -26,13 +41,19 @@ class Cudan::Main
26
41
  puts opts.to_s
27
42
  exit
28
43
  end
29
- if /^\/(.*)\/$/ =~ @query
30
- klass = Cudan::RegexpCudan
44
+ if /^\/(.+)\/$/ =~ @query
45
+ @mode = :regexp
31
46
  @query = $~[1]
32
- else
33
- klass = Cudan::XpathCudan
34
47
  end
35
- instance = klass::new
48
+ case @mode
49
+ when :regexp
50
+ @klass = Cudan::RegexpCudan
51
+ when :css
52
+ @klass = Cudan::XpathCudan
53
+ when :xpath
54
+ @klass = Cudan::XpathCudan
55
+ end
56
+ instance = @klass::new
36
57
  instance.set_header('UserAgent', @ua) if @ua
37
58
  instance.showbody = @showbody
38
59
  instance.execute(@query, @expects, @url)
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 0
8
- - 4
9
- version: 0.0.4
8
+ - 5
9
+ version: 0.0.5
10
10
  platform: ruby
11
11
  authors:
12
12
  - takada-at