scraper 0.0.1.pre
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 +7 -0
- data/lib/scraper.rb +64 -0
- metadata +46 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA1:
|
|
3
|
+
metadata.gz: 1bc424512e35d84f79b24f1ea2552c359e9f3ed6
|
|
4
|
+
data.tar.gz: 982fe508e27ba4f800f2bd240414a0d1835eded3
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 6df32a57fe080f6155a6939f8123dd071a6443daed2c4ccf5fcff2a147312fd5bfdee483520b92e09afb9f5d0a4b742e43d9ae1292ef1793c8692df067b18b93
|
|
7
|
+
data.tar.gz: 1d911d9bd9482a8c867e082fca72e886ea0ead540277c473a07e616ab184406614cf56089f6ababd5affa8edb8b5c37c6154777e774758eb4a8eeefa431cd722
|
data/lib/scraper.rb
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
# Load Rubygems
|
|
2
|
+
require 'bundler'
|
|
3
|
+
Bundler.require
|
|
4
|
+
|
|
5
|
+
# Load Ruby Libraries
|
|
6
|
+
require 'open-uri'
|
|
7
|
+
|
|
8
|
+
class Scraper
|
|
9
|
+
attr_reader :found, :results
|
|
10
|
+
attr_accessor :query
|
|
11
|
+
|
|
12
|
+
alias_method :found?, :found
|
|
13
|
+
|
|
14
|
+
def initialize(query)
|
|
15
|
+
@query = query
|
|
16
|
+
@found = false
|
|
17
|
+
@results = {}
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def scrape(url)
|
|
21
|
+
result = []
|
|
22
|
+
|
|
23
|
+
check_location(url, result)
|
|
24
|
+
result = format_result(result)
|
|
25
|
+
@results[url] = result
|
|
26
|
+
|
|
27
|
+
update_found(url)
|
|
28
|
+
|
|
29
|
+
result
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
private
|
|
33
|
+
|
|
34
|
+
def check_location(url, result)
|
|
35
|
+
open(url) do |f|
|
|
36
|
+
f.each do |line|
|
|
37
|
+
if /#{@query}/i =~ line
|
|
38
|
+
result << f.lineno
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
def format_result(result)
|
|
45
|
+
if result.empty?
|
|
46
|
+
result = false
|
|
47
|
+
elsif result.length == 1
|
|
48
|
+
result = result[0]
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
def update_and_format_results(result, url)
|
|
53
|
+
result = format_result(result)
|
|
54
|
+
@results[url] = result
|
|
55
|
+
|
|
56
|
+
result
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
def update_found(url)
|
|
60
|
+
unless @results[url] == false
|
|
61
|
+
@found = true
|
|
62
|
+
end
|
|
63
|
+
end
|
|
64
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: scraper
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.0.1.pre
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- M. Maxwell Watson
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: bin
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2014-07-22 00:00:00.000000000 Z
|
|
12
|
+
dependencies: []
|
|
13
|
+
description: Scraper scrapes supplied URLs for a query and returns the line numbers
|
|
14
|
+
of any matches.
|
|
15
|
+
email:
|
|
16
|
+
- maxwell.watson@ogilvy.com
|
|
17
|
+
executables: []
|
|
18
|
+
extensions: []
|
|
19
|
+
extra_rdoc_files: []
|
|
20
|
+
files:
|
|
21
|
+
- lib/scraper.rb
|
|
22
|
+
homepage: http://rubygems.org/gems/hola
|
|
23
|
+
licenses:
|
|
24
|
+
- MIT
|
|
25
|
+
metadata: {}
|
|
26
|
+
post_install_message:
|
|
27
|
+
rdoc_options: []
|
|
28
|
+
require_paths:
|
|
29
|
+
- lib
|
|
30
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
31
|
+
requirements:
|
|
32
|
+
- - ">="
|
|
33
|
+
- !ruby/object:Gem::Version
|
|
34
|
+
version: '0'
|
|
35
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
36
|
+
requirements:
|
|
37
|
+
- - ">"
|
|
38
|
+
- !ruby/object:Gem::Version
|
|
39
|
+
version: 1.3.1
|
|
40
|
+
requirements: []
|
|
41
|
+
rubyforge_project:
|
|
42
|
+
rubygems_version: 2.2.2
|
|
43
|
+
signing_key:
|
|
44
|
+
specification_version: 4
|
|
45
|
+
summary: A simple web scraper.
|
|
46
|
+
test_files: []
|