web_grep 1.0.3 → 1.1.0

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: 4bf91faade5a4b67c1a91675df523b6d53a04caa
4
- data.tar.gz: 810607fcda4f2fb306b5ec86118eb5ad4bce1a96
3
+ metadata.gz: 3163f6e8b38d601244de947a2a915d60245ae6bd
4
+ data.tar.gz: 31ea7e0fa494d940af32d07afec2a2ca38d3c22c
5
5
  SHA512:
6
- metadata.gz: 8bbbb7a90e064b24630c813b5d2fe4d381b3c49ca6701d691524726e32c5055265bca1ab4f38b08707291685b04831174956671d86ff038a7f099e1e83751702
7
- data.tar.gz: b5576ac40ceba64337e99d3c9510c0fa5a0740dba37378395d39128b7ad0e2c73fe1f679b03d4949fe88b172b901ac775b9e7c82269388bb361303bf28514fe7
6
+ metadata.gz: eb63d0c37f10d083f864222d29a11a5f4219aba9ec24f2ed1e7f62038abc4b8765e65f6ebd20aaf2e8128ebc82e3efcb6481f5d5427a2c8bddc1ef293b91ca3b
7
+ data.tar.gz: bb42430ce81efd10179d579bf983e8db39a4adef6cf5eca21a4a29a04a06b622fed0fa5972231c7bfe3a54bd3059848719d903444f47f47ca8c5d1b0470e502c
data/README.md CHANGED
@@ -23,7 +23,9 @@ Options
23
23
  -f, --file [file_path] Search in file: "../index.html"
24
24
  -u, --url [url] Search in URL: "ya.ru"
25
25
  -q, --quite Show only xpaths
26
- -c, --only-count Show only count
26
+ -c, --count Show only count
27
+ -x, --xpath Show xpaths to founded
28
+ -s, --css Show css paths to founded
27
29
  -v, --version Show version
28
30
  -h, --help Show this help
29
31
  ```
data/bin/web_grep CHANGED
@@ -7,8 +7,7 @@ require 'web_grep'
7
7
  options = {}
8
8
  OptionParser.new do |opt|
9
9
  opt.banner = "Usage:\n web_grep WORD WEB_PAGE [OPTIONS]"
10
- opt.separator ''
11
- opt.separator 'Options'
10
+ opt.separator "\nOptions"
12
11
 
13
12
  opt.on('-w', '--word [word]', String, 'Searcheble word or RegExp') do |word|
14
13
  options[:word] = word
@@ -26,10 +25,18 @@ OptionParser.new do |opt|
26
25
  options[:quite] = q
27
26
  end
28
27
 
29
- opt.on('-c', '--only-count', 'Show only count') do |c|
28
+ opt.on('-c', '--count', 'Show only count') do |c|
30
29
  options[:only_count] = c
31
30
  end
32
31
 
32
+ opt.on('-x', '--xpath', 'Show xpaths to founded') do |x|
33
+ options[:xpath] = x
34
+ end
35
+
36
+ opt.on('-s', '--css', 'Show css paths to founded') do |s|
37
+ options[:css] = s
38
+ end
39
+
33
40
  opt.on_tail('-v', '--version', 'Show version') do
34
41
  puts WebGrep::VERSION
35
42
  exit
@@ -49,5 +56,9 @@ greped = WebGrep::Grep.new(
49
56
  quite: options[:quite]
50
57
  ).grep!
51
58
 
52
- puts greped if !options[:only_count]
59
+ greped.each do |l|
60
+ puts "\033[32;1m" + "CSS path: #{l.css_path}" if options[:css]
61
+ puts "\033[32;1m" + "XPath: #{l.path}" if options[:xpath]
62
+ puts "\033[0m" + "Matched content: #{l.content}" unless options[:quite]
63
+ end unless options[:only_count]
53
64
  puts "#{"\033[32;1m"}Found #{greped.count}#{"\033[0m"}"
data/lib/web_grep/grep.rb CHANGED
@@ -1,6 +1,8 @@
1
1
  require 'nokogiri'
2
2
  require 'open-uri'
3
3
 
4
+ require 'pry'
5
+
4
6
  module WebGrep
5
7
  class Grep
6
8
  def initialize(word:,url:,file:,quite:)
@@ -18,9 +20,6 @@ module WebGrep
18
20
  e.content
19
21
  .encode('UTF-8', 'binary', invalid: :replace, undef: :replace, replace: '')
20
22
  .match /#{@word}/
21
- end.map do |l|
22
- "#{"\033[32;1m"}XPath: #{l.path}#{"\033[0m"}" \
23
- "#{"\n\tMatched content: #{l.content}" if !@quite}"
24
23
  end
25
24
  rescue SocketError
26
25
  raise 'Bad url or connection!'
@@ -1,3 +1,3 @@
1
1
  module WebGrep
2
- VERSION = '1.0.3'
2
+ VERSION = '1.1.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.0.3
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Vladislav Petrov