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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3163f6e8b38d601244de947a2a915d60245ae6bd
4
- data.tar.gz: 31ea7e0fa494d940af32d07afec2a2ca38d3c22c
3
+ metadata.gz: ae71de152641bb649f6005b6ecedd69f0ba1d9e5
4
+ data.tar.gz: 231a126eaa61a90283296710abaec4573b8cc56b
5
5
  SHA512:
6
- metadata.gz: eb63d0c37f10d083f864222d29a11a5f4219aba9ec24f2ed1e7f62038abc4b8765e65f6ebd20aaf2e8128ebc82e3efcb6481f5d5427a2c8bddc1ef293b91ca3b
7
- data.tar.gz: bb42430ce81efd10179d579bf983e8db39a4adef6cf5eca21a4a29a04a06b622fed0fa5972231c7bfe3a54bd3059848719d903444f47f47ca8c5d1b0470e502c
6
+ metadata.gz: 57650d0e7e4ee78641e1d5d23c7907a0ee67cf51b5d963cdd328686bcd1bd11d9275a722dfebd4c7b71235f516b362280d8d1d2a6e55084aa7cdbdd7c7067e88
7
+ data.tar.gz: da4cedd3d25dbe69d200a5f7a353b9f6727d6c9e51f0450c5f5b797cf58bdb265244c9cbec66263493f9f4a1de3c2efa2f2496653f537972d092a5d33d2d50fb
@@ -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 unless options[:only_count]
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"}"
@@ -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
- raise 'Should set one of params, url or file!'
11
- end
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)).search('[text()*=""]').select do |e|
20
- e.content
21
- .encode('UTF-8', 'binary', invalid: :replace, undef: :replace, replace: '')
22
- .match /#{@word}/
23
- end
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
@@ -1,3 +1,3 @@
1
1
  module WebGrep
2
- VERSION = '1.1.0'
2
+ VERSION = '1.2.0'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: web_grep
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Vladislav Petrov