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 +12 -0
- data/lib/cudan.rb +1 -1
- data/lib/cudan/base_cudan.rb +2 -0
- data/lib/cudan/main.rb +26 -5
- metadata +2 -2
data/CHANGES
CHANGED
data/lib/cudan.rb
CHANGED
data/lib/cudan/base_cudan.rb
CHANGED
@@ -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
|
data/lib/cudan/main.rb
CHANGED
@@ -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 /^\/(
|
30
|
-
|
44
|
+
if /^\/(.+)\/$/ =~ @query
|
45
|
+
@mode = :regexp
|
31
46
|
@query = $~[1]
|
32
|
-
else
|
33
|
-
klass = Cudan::XpathCudan
|
34
47
|
end
|
35
|
-
|
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)
|