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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c3227a0d2994fdaf379572fc7dc089fb772b70f6
4
- data.tar.gz: 197b8a5aa3088295888e4349a095684f1ca74656
3
+ metadata.gz: a6cf41b7dc06a31a4e7f297af3c4f31347c2225b
4
+ data.tar.gz: 30b46cf335dc3c851c2678ca821c31c5195fb084
5
5
  SHA512:
6
- metadata.gz: ade710caac2058b7d3522c9cb4742d1b9be116513c75e55ff204212abb9d789b80ed1b35f0695aa7471bb4959d85918864b2c354aae94f5889b3bf5de1ca7a9f
7
- data.tar.gz: e2700740630b8fcf74dc9136358f2f8c1b61389297430907c31d099026f17c064f5111b152e78133b600798a3af74b7a71f3d77a647733bb480e32f5acd54857
6
+ metadata.gz: 56ad7babc92330e88045709384dffea4a9ef855e1864b5b040c700925081edbafe8a02df3b797645eb0268aa864a3124bafd5e834763872a0b3186f84fbd05e4
7
+ data.tar.gz: 5d63c2a62958874d1271feb4a7212c7233f78cec52b0d896fd3c7f1fd9682852defd23382b3c3196f7fa20b470016cb489566561b8fd7146d33c856c26e1eafc
data/.gitignore ADDED
@@ -0,0 +1,3 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
data/Gemfile ADDED
@@ -0,0 +1,9 @@
1
+ source "https://rubygems.org"
2
+
3
+ gemspec
4
+
5
+ gem 'rake'
6
+ gem 'bump'
7
+ gem 'minitest'
8
+ gem 'minitest-rg'
9
+ gem 'minitest-around'
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
@@ -0,0 +1,7 @@
1
+ require 'rake/testtask'
2
+ require 'bump/tasks'
3
+
4
+ Rake::TestTask.new :default do |test|
5
+ test.pattern = 'test/**/*_test.rb'
6
+ test.verbose = true
7
+ end
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
@@ -1,3 +1,3 @@
1
1
  module WebGrep
2
- VERSION = '0.0.1'
2
+ VERSION = '1.0.0'
3
3
  end
data/lib/web_grep.rb CHANGED
@@ -1,3 +1,4 @@
1
1
  module WebGrep
2
2
  autoload :VERSION, 'web_grep/version'
3
+ autoload :Grep, 'web_grep/grep'
3
4
  end
@@ -0,0 +1,4 @@
1
+ require 'minitest/autorun'
2
+ require 'minitest/rg'
3
+ require 'minitest/around'
4
+ $LOAD_PATH.unshift File.expand_path("../../lib", __FILE__)
@@ -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}/*`.split
19
- s.executables = `git ls-files -- bin/*`.split.map{ |f| File.basename(f) }
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.1
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