web_grep 1.1.0 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/web_grep +2 -2
- data/lib/web_grep/grep.rb +9 -13
- data/lib/web_grep/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ae71de152641bb649f6005b6ecedd69f0ba1d9e5
|
4
|
+
data.tar.gz: 231a126eaa61a90283296710abaec4573b8cc56b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 57650d0e7e4ee78641e1d5d23c7907a0ee67cf51b5d963cdd328686bcd1bd11d9275a722dfebd4c7b71235f516b362280d8d1d2a6e55084aa7cdbdd7c7067e88
|
7
|
+
data.tar.gz: da4cedd3d25dbe69d200a5f7a353b9f6727d6c9e51f0450c5f5b797cf58bdb265244c9cbec66263493f9f4a1de3c2efa2f2496653f537972d092a5d33d2d50fb
|
data/bin/web_grep
CHANGED
@@ -60,5 +60,5 @@ greped.each do |l|
|
|
60
60
|
puts "\033[32;1m" + "CSS path: #{l.css_path}" if options[:css]
|
61
61
|
puts "\033[32;1m" + "XPath: #{l.path}" if options[:xpath]
|
62
62
|
puts "\033[0m" + "Matched content: #{l.content}" unless options[:quite]
|
63
|
-
end
|
64
|
-
puts "#{"\033[32;1m"}Found #{greped.count}#{"\033[0m"}"
|
63
|
+
end if greped && !options[:only_count]
|
64
|
+
puts "#{"\033[32;1m"}Found #{greped.to_a.count}#{"\033[0m"}"
|
data/lib/web_grep/grep.rb
CHANGED
@@ -1,26 +1,22 @@
|
|
1
1
|
require 'nokogiri'
|
2
2
|
require 'open-uri'
|
3
3
|
|
4
|
-
require 'pry'
|
5
|
-
|
6
4
|
module WebGrep
|
7
5
|
class Grep
|
8
6
|
def initialize(word:,url:,file:,quite:)
|
9
|
-
if file && url
|
10
|
-
|
11
|
-
|
12
|
-
if url && !url.match('http://|https://')
|
13
|
-
url = "http://#{url}"
|
14
|
-
end
|
7
|
+
raise 'Should set one of params, url or file!' if file && url
|
8
|
+
url = "http://#{url}" if url && !url.match('http[s]{0,1}://')
|
9
|
+
|
15
10
|
@word, @url, @file, @quite = word, url, file, quite
|
16
11
|
end
|
17
12
|
|
18
13
|
def grep!
|
19
|
-
Nokogiri::XML(open(@url || @file)).
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
14
|
+
Nokogiri::XML(open(@url || @file)).
|
15
|
+
xpath ".//text()[regex(., '#{@word}')]", Class.new {
|
16
|
+
def regex(node_set, regex)
|
17
|
+
node_set.find_all { |node| node.content.match regex }
|
18
|
+
end
|
19
|
+
}.new
|
24
20
|
rescue SocketError
|
25
21
|
raise 'Bad url or connection!'
|
26
22
|
end
|
data/lib/web_grep/version.rb
CHANGED