web_grep 1.0.2 → 1.0.3

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7567e98e689615a3946ffb3d60f9d02ff2b131fd
4
- data.tar.gz: b917f9c7792fcb31f28ca87e0ff71e96ccb407d2
3
+ metadata.gz: 4bf91faade5a4b67c1a91675df523b6d53a04caa
4
+ data.tar.gz: 810607fcda4f2fb306b5ec86118eb5ad4bce1a96
5
5
  SHA512:
6
- metadata.gz: db7c7f455b29b933b7b59ca79b3836f148a4945e93a4e9972926e306063ba4b97e362967e3b27b48a5f4cda3cfb471701292f494d0ce86cddd5b8250ba9e75bc
7
- data.tar.gz: 7389a1844f1605be972d0af5397b17f9c06cea6256482fa097750c97eb7e5a6a7fbb82ec9c4ce2ac11d11da18f535ee89a88f76196669888422f07edaef435db
6
+ metadata.gz: 8bbbb7a90e064b24630c813b5d2fe4d381b3c49ca6701d691524726e32c5055265bca1ab4f38b08707291685b04831174956671d86ff038a7f099e1e83751702
7
+ data.tar.gz: b5576ac40ceba64337e99d3c9510c0fa5a0740dba37378395d39128b7ad0e2c73fe1f679b03d4949fe88b172b901ac775b9e7c82269388bb361303bf28514fe7
data/README.md CHANGED
@@ -13,6 +13,25 @@ gem install web_grep
13
13
  Usage
14
14
  =====
15
15
 
16
+ ```
17
+ ~ $ web_grep --help
18
+ Usage:
19
+ web_grep WORD WEB_PAGE [OPTIONS]
20
+
21
+ Options
22
+ -w, --word [word] Searcheble word or RegExp
23
+ -f, --file [file_path] Search in file: "../index.html"
24
+ -u, --url [url] Search in URL: "ya.ru"
25
+ -q, --quite Show only xpaths
26
+ -c, --only-count Show only count
27
+ -v, --version Show version
28
+ -h, --help Show this help
29
+ ```
30
+
31
+ ```
32
+ ~ $ web_grep Home https://www.yahoo.com -c
33
+ Found 33
34
+ ```
16
35
 
17
36
  Copyright
18
37
  =========
data/bin/web_grep CHANGED
@@ -22,6 +22,14 @@ OptionParser.new do |opt|
22
22
  options[:url] = url
23
23
  end
24
24
 
25
+ opt.on('-q', '--quite', 'Show only xpaths') do |q|
26
+ options[:quite] = q
27
+ end
28
+
29
+ opt.on('-c', '--only-count', 'Show only count') do |c|
30
+ options[:only_count] = c
31
+ end
32
+
25
33
  opt.on_tail('-v', '--version', 'Show version') do
26
34
  puts WebGrep::VERSION
27
35
  exit
@@ -35,10 +43,11 @@ OptionParser.new do |opt|
35
43
  end.parse!
36
44
 
37
45
  greped = WebGrep::Grep.new(
38
- word: options[:word] || ARGV[0],
39
- url: options[:url ] || ARGV[1],
40
- file: options[:file]
46
+ word: options[:word] || ARGV[0],
47
+ url: options[:url ] || ARGV[1],
48
+ file: options[:file],
49
+ quite: options[:quite]
41
50
  ).grep!
42
51
 
43
- puts greped
52
+ puts greped if !options[:only_count]
44
53
  puts "#{"\033[32;1m"}Found #{greped.count}#{"\033[0m"}"
data/lib/web_grep/grep.rb CHANGED
@@ -3,14 +3,14 @@ require 'open-uri'
3
3
 
4
4
  module WebGrep
5
5
  class Grep
6
- def initialize(word:,url:,file:)
6
+ def initialize(word:,url:,file:,quite:)
7
7
  if file && url
8
8
  raise 'Should set one of params, url or file!'
9
9
  end
10
10
  if url && !url.match('http://|https://')
11
11
  url = "http://#{url}"
12
12
  end
13
- @word, @url, @file = word, url, file
13
+ @word, @url, @file, @quite = word, url, file, quite
14
14
  end
15
15
 
16
16
  def grep!
@@ -19,8 +19,8 @@ module WebGrep
19
19
  .encode('UTF-8', 'binary', invalid: :replace, undef: :replace, replace: '')
20
20
  .match /#{@word}/
21
21
  end.map do |l|
22
- "#{"\033[32;1m"}XPath: #{l.path}#{"\033[0m"}\n" \
23
- "\tMatched content: #{l.content}"
22
+ "#{"\033[32;1m"}XPath: #{l.path}#{"\033[0m"}" \
23
+ "#{"\n\tMatched content: #{l.content}" if !@quite}"
24
24
  end
25
25
  rescue SocketError
26
26
  raise 'Bad url or connection!'
@@ -1,3 +1,3 @@
1
1
  module WebGrep
2
- VERSION = '1.0.2'
2
+ VERSION = '1.0.3'
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.0.2
4
+ version: 1.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Vladislav Petrov