web_grep 0.0.1 → 1.0.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 +4 -4
- data/.gitignore +3 -0
- data/Gemfile +9 -0
- data/README.md +22 -0
- data/Rakefile +7 -0
- data/bin/web_grep +44 -0
- data/lib/web_grep/grep.rb +29 -0
- data/lib/web_grep/version.rb +1 -1
- data/lib/web_grep.rb +1 -0
- data/test/test_helper.rb +4 -0
- data/test/web_grep_test.rb +18 -0
- data/web_grep.gemspec +2 -2
- metadata +14 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a6cf41b7dc06a31a4e7f297af3c4f31347c2225b
|
4
|
+
data.tar.gz: 30b46cf335dc3c851c2678ca821c31c5195fb084
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 56ad7babc92330e88045709384dffea4a9ef855e1864b5b040c700925081edbafe8a02df3b797645eb0268aa864a3124bafd5e834763872a0b3186f84fbd05e4
|
7
|
+
data.tar.gz: 5d63c2a62958874d1271feb4a7212c7233f78cec52b0d896fd3c7f1fd9682852defd23382b3c3196f7fa20b470016cb489566561b8fd7146d33c856c26e1eafc
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
web_grep
|
2
|
+
-------
|
3
|
+
|
4
|
+
Web grep is a grep for web pages.
|
5
|
+
|
6
|
+
Installation
|
7
|
+
============
|
8
|
+
|
9
|
+
```
|
10
|
+
gem install web_grep
|
11
|
+
```
|
12
|
+
|
13
|
+
Usage
|
14
|
+
=====
|
15
|
+
|
16
|
+
|
17
|
+
Copyright
|
18
|
+
=========
|
19
|
+
|
20
|
+
Copyright (c) 2014 Vladislav Petrov.
|
21
|
+
|
22
|
+
See MIT-LICENSE.md for further details.
|
data/Rakefile
ADDED
data/bin/web_grep
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
$LOAD_PATH << './lib'
|
3
|
+
|
4
|
+
require 'optparse'
|
5
|
+
require 'web_grep'
|
6
|
+
|
7
|
+
options = {}
|
8
|
+
OptionParser.new do |opt|
|
9
|
+
opt.banner = "Usage:\n web_grep WORD WEB_PAGE [OPTIONS]"
|
10
|
+
opt.separator ''
|
11
|
+
opt.separator 'Options'
|
12
|
+
|
13
|
+
opt.on('-w', '--word [word]', String, 'Searcheble word or RegExp') do |word|
|
14
|
+
options[:word] = word
|
15
|
+
end
|
16
|
+
|
17
|
+
opt.on('-f', '--file [file_path]', String, 'Search in file: "../index.html"') do |file|
|
18
|
+
options[:file] = file
|
19
|
+
end
|
20
|
+
|
21
|
+
opt.on('-u', '--url [url]', String, 'Search in URL: "ya.ru"') do |url|
|
22
|
+
options[:url] = url
|
23
|
+
end
|
24
|
+
|
25
|
+
opt.on_tail('-v', '--version', 'Show version') do
|
26
|
+
puts WebGrep::VERSION
|
27
|
+
exit
|
28
|
+
end
|
29
|
+
|
30
|
+
opt.on_tail('-h', '--help', 'Show this help') { puts opt; exit }
|
31
|
+
|
32
|
+
if ARGV.empty? && options.empty?
|
33
|
+
opt.on { puts opt; exit }
|
34
|
+
end
|
35
|
+
end.parse!
|
36
|
+
|
37
|
+
greped = WebGrep::Grep.new(
|
38
|
+
word: options[:word] || ARGV[0],
|
39
|
+
url: options[:url ] || ARGV[1],
|
40
|
+
file: options[:file]
|
41
|
+
).grep!
|
42
|
+
|
43
|
+
puts greped
|
44
|
+
puts "#{"\033[32;1m"}Found #{greped.count}#{"\033[0m"}"
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'nokogiri'
|
2
|
+
require 'open-uri'
|
3
|
+
|
4
|
+
module WebGrep
|
5
|
+
class Grep
|
6
|
+
def initialize(word:,url:,file:)
|
7
|
+
if file && url
|
8
|
+
raise 'Should set one of params, url or file!'
|
9
|
+
end
|
10
|
+
if url && !url.match('http://|https://')
|
11
|
+
url = "http://#{url}"
|
12
|
+
end
|
13
|
+
@word, @url, @file = word, url, file
|
14
|
+
end
|
15
|
+
|
16
|
+
def grep!
|
17
|
+
Nokogiri::XML(open(@url || @file)).search('[text()*=""]').select do |e|
|
18
|
+
e.content
|
19
|
+
.encode('UTF-8', 'binary', invalid: :replace, undef: :replace, replace: '')
|
20
|
+
.match /#{@word}/
|
21
|
+
end.map do |l|
|
22
|
+
"#{"\033[32;1m"}XPath: #{l.path}#{"\033[0m"}\n" \
|
23
|
+
"\tMatched content: #{l.content}"
|
24
|
+
end
|
25
|
+
rescue SocketError
|
26
|
+
raise 'Bad url or connection!'
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
data/lib/web_grep/version.rb
CHANGED
data/lib/web_grep.rb
CHANGED
data/test/test_helper.rb
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
require_relative 'test_helper'
|
2
|
+
require 'tmpdir'
|
3
|
+
|
4
|
+
describe WebGrep do
|
5
|
+
describe 'CLI' do
|
6
|
+
def web_grep(command='')
|
7
|
+
`#{Bundler.root}/bin/web_grep #{command}`
|
8
|
+
end
|
9
|
+
|
10
|
+
it 'shows --version' do
|
11
|
+
web_grep('--version').must_include WebGrep::VERSION
|
12
|
+
end
|
13
|
+
|
14
|
+
it 'shows --help' do
|
15
|
+
web_grep('--help').must_include 'web_grep'
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
data/web_grep.gemspec
CHANGED
@@ -15,7 +15,7 @@ Gem::Specification.new 'web_grep', WebGrep::VERSION do |s|
|
|
15
15
|
s.required_rubygems_version = '>= 2.3.0'
|
16
16
|
|
17
17
|
s.files = `git ls-files`.split
|
18
|
-
s.test_files = `git ls-files -- {test,spec,features}
|
19
|
-
s.executables = `git ls-files -- bin
|
18
|
+
s.test_files = `git ls-files -- {test,spec,features}`.split
|
19
|
+
s.executables = `git ls-files -- bin`.split.map{ |f| File.basename(f) }
|
20
20
|
s.require_paths = ['lib']
|
21
21
|
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: 0.0
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Vladislav Petrov
|
@@ -12,13 +12,22 @@ date: 2014-06-26 00:00:00.000000000 Z
|
|
12
12
|
dependencies: []
|
13
13
|
description: Web grep is a grep for web pages
|
14
14
|
email: electronicchest@gmail.com
|
15
|
-
executables:
|
15
|
+
executables:
|
16
|
+
- web_grep
|
16
17
|
extensions: []
|
17
18
|
extra_rdoc_files: []
|
18
19
|
files:
|
20
|
+
- ".gitignore"
|
21
|
+
- Gemfile
|
19
22
|
- MIT-LICENSE.md
|
23
|
+
- README.md
|
24
|
+
- Rakefile
|
25
|
+
- bin/web_grep
|
20
26
|
- lib/web_grep.rb
|
27
|
+
- lib/web_grep/grep.rb
|
21
28
|
- lib/web_grep/version.rb
|
29
|
+
- test/test_helper.rb
|
30
|
+
- test/web_grep_test.rb
|
22
31
|
- web_grep.gemspec
|
23
32
|
homepage: http://rubygems.org/gems/web_grep
|
24
33
|
licenses:
|
@@ -44,4 +53,6 @@ rubygems_version: 2.3.0
|
|
44
53
|
signing_key:
|
45
54
|
specification_version: 4
|
46
55
|
summary: Web grep is a grep for web pages
|
47
|
-
test_files:
|
56
|
+
test_files:
|
57
|
+
- test/test_helper.rb
|
58
|
+
- test/web_grep_test.rb
|