wgit 0.0.18 → 0.2.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/lib/wgit.rb +0 -1
- data/lib/wgit/assertable.rb +20 -23
- data/lib/wgit/core_ext.rb +6 -14
- data/lib/wgit/crawler.rb +94 -183
- data/lib/wgit/database/database.rb +209 -185
- data/lib/wgit/database/model.rb +7 -7
- data/lib/wgit/document.rb +281 -241
- data/lib/wgit/indexer.rb +99 -92
- data/lib/wgit/logger.rb +5 -1
- data/lib/wgit/url.rb +171 -185
- data/lib/wgit/utils.rb +57 -68
- data/lib/wgit/version.rb +1 -1
- metadata +86 -60
- data/CHANGELOG.md +0 -61
- data/LICENSE.txt +0 -21
- data/README.md +0 -361
- data/TODO.txt +0 -34
- data/lib/wgit/database/connection_details.rb +0 -41
data/LICENSE.txt
DELETED
@@ -1,21 +0,0 @@
|
|
1
|
-
The MIT License (MIT)
|
2
|
-
|
3
|
-
Copyright (c) 2019 Michael Telford
|
4
|
-
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
7
|
-
in the Software without restriction, including without limitation the rights
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
10
|
-
furnished to do so, subject to the following conditions:
|
11
|
-
|
12
|
-
The above copyright notice and this permission notice shall be included in
|
13
|
-
all copies or substantial portions of the Software.
|
14
|
-
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
-
THE SOFTWARE.
|
data/README.md
DELETED
@@ -1,361 +0,0 @@
|
|
1
|
-
# Wgit
|
2
|
-
|
3
|
-
[](https://rubygems.org/gems/wgit)
|
4
|
-
[](https://rubygems.org/gems/wgit)
|
5
|
-
[](https://travis-ci.org/michaeltelford/wgit)
|
6
|
-
[](https://www.rubydoc.info/gems/wgit)
|
7
|
-
[](https://www.codacy.com/app/michaeltelford/wgit?utm_source=github.com&utm_medium=referral&utm_content=michaeltelford/wgit&utm_campaign=Badge_Grade)
|
8
|
-
|
9
|
-
---
|
10
|
-
|
11
|
-
Wgit is a Ruby gem similar in nature to GNU's `wget` tool. It provides an easy to use API for programmatic web scraping, indexing and searching.
|
12
|
-
|
13
|
-
Fundamentally, Wgit is a WWW indexer/scraper which crawls URL's, retrieves and serialises their page contents for later use. You can use Wgit to copy entire websites if required. Wgit also provides a means to search indexed documents stored in a database. Therefore, this library provides the main components of a WWW search engine. The Wgit API is easily extended allowing you to pull out the parts of a webpage that are important to you, the code snippets or tables for example. As Wgit is a library, it has uses in many different application types.
|
14
|
-
|
15
|
-
Check out this [example application](https://search-engine-rb.herokuapp.com) - a search engine (see its [repository](https://github.com/michaeltelford/search_engine)) built using Wgit and Sinatra, deployed to Heroku. Heroku's free tier is used so the initial page load may be slow. Try searching for "Ruby" or something else that's Ruby related.
|
16
|
-
|
17
|
-
## Table Of Contents
|
18
|
-
|
19
|
-
1. [Installation](#Installation)
|
20
|
-
2. [Basic Usage](#Basic-Usage)
|
21
|
-
3. [Documentation](#Documentation)
|
22
|
-
4. [Practical Examples](#Practical-Examples)
|
23
|
-
5. [Practical Database Example](#Practical-Database-Example)
|
24
|
-
6. [Extending The API](#Extending-The-API)
|
25
|
-
7. [Caveats](#Caveats)
|
26
|
-
8. [Executable](#Executable)
|
27
|
-
9. [Change Log](#Change-Log)
|
28
|
-
10. [Development](#Development)
|
29
|
-
11. [Contributing](#Contributing)
|
30
|
-
12. [License](#License)
|
31
|
-
|
32
|
-
## Installation
|
33
|
-
|
34
|
-
Add this line to your application's `Gemfile`:
|
35
|
-
|
36
|
-
```ruby
|
37
|
-
gem 'wgit'
|
38
|
-
```
|
39
|
-
|
40
|
-
And then execute:
|
41
|
-
|
42
|
-
$ bundle
|
43
|
-
|
44
|
-
Or install it yourself as:
|
45
|
-
|
46
|
-
$ gem install wgit
|
47
|
-
|
48
|
-
## Basic Usage
|
49
|
-
|
50
|
-
Below shows an example of API usage in action and gives an idea of how you can use Wgit in your own code.
|
51
|
-
|
52
|
-
```ruby
|
53
|
-
require 'wgit'
|
54
|
-
|
55
|
-
crawler = Wgit::Crawler.new
|
56
|
-
url = Wgit::Url.new "https://wikileaks.org/What-is-Wikileaks.html"
|
57
|
-
|
58
|
-
doc = crawler.crawl url
|
59
|
-
|
60
|
-
doc.class # => Wgit::Document
|
61
|
-
doc.stats # => {
|
62
|
-
# :url=>44, :html=>28133, :title=>17, :keywords=>0,
|
63
|
-
# :links=>35, :text_snippets=>67, :text_bytes=>13735
|
64
|
-
#}
|
65
|
-
|
66
|
-
# doc responds to the following methods:
|
67
|
-
Wgit::Document.instance_methods(false).sort # => [
|
68
|
-
# :==, :[], :author, :base, :base_url, :css, :date_crawled, :doc, :empty?,
|
69
|
-
# :external_links, :external_urls, :find_in_html, :find_in_object, :html,
|
70
|
-
# :init_nokogiri, :internal_absolute_links, :internal_full_links,
|
71
|
-
# :internal_links, :keywords, :links, :relative_absolute_links,
|
72
|
-
# :relative_absolute_urls, :relative_full_links, :relative_full_urls,
|
73
|
-
# :relative_links, :relative_urls, :score, :search, :search!, :size, :stats,
|
74
|
-
# :text, :title, :to_h, :to_json, :url, :xpath
|
75
|
-
# ]
|
76
|
-
|
77
|
-
results = doc.search "corruption"
|
78
|
-
results.first # => "ial materials involving war, spying and corruption.
|
79
|
-
# It has so far published more"
|
80
|
-
```
|
81
|
-
|
82
|
-
## Documentation
|
83
|
-
|
84
|
-
100% of Wgit's code is documented using [YARD](https://yardoc.org/), deployed to [Rubydocs](https://www.rubydoc.info/gems/wgit). This greatly benefits developers in using Wgit in their own programs. Another good source of information (as to how the library behaves) are the tests. Also, see the [Practical Examples](#Practical-Examples) section below for real working examples of Wgit in action.
|
85
|
-
|
86
|
-
## Practical Examples
|
87
|
-
|
88
|
-
Below are some practical examples of Wgit in use. You can copy and run the code for yourself.
|
89
|
-
|
90
|
-
### WWW HTML Indexer
|
91
|
-
|
92
|
-
See the `Wgit::Indexer#index_the_web` documentation and source code for an already built example of a WWW HTML indexer. It will crawl any external url's (in the database) and index their markup for later use, be it searching or otherwise. It will literally crawl the WWW forever if you let it!
|
93
|
-
|
94
|
-
See the [Practical Database Example](#Practical-Database-Example) for information on how to setup a database for use with Wgit.
|
95
|
-
|
96
|
-
### Website Downloader
|
97
|
-
|
98
|
-
Wgit uses itself to download and save fixture webpages to disk (used in tests). See the script [here](https://github.com/michaeltelford/wgit/blob/master/test/mock/save_site.rb) and edit it for your own purposes.
|
99
|
-
|
100
|
-
### Broken Link Finder
|
101
|
-
|
102
|
-
The `broken_link_finder` gem uses Wgit under the hood to find and report a website's broken links. Check out its [repository](https://github.com/michaeltelford/broken_link_finder) for more details.
|
103
|
-
|
104
|
-
### CSS Indexer
|
105
|
-
|
106
|
-
The below script downloads the contents of the first css link found on Facebook's index page.
|
107
|
-
|
108
|
-
```ruby
|
109
|
-
require 'wgit'
|
110
|
-
require 'wgit/core_ext' # Provides the String#to_url and Enumerable#to_urls methods.
|
111
|
-
|
112
|
-
crawler = Wgit::Crawler.new
|
113
|
-
url = "https://www.facebook.com".to_url
|
114
|
-
|
115
|
-
doc = crawler.crawl url
|
116
|
-
|
117
|
-
# Provide your own xpath (or css selector) to search the HTML using Nokogiri underneath.
|
118
|
-
hrefs = doc.xpath "//link[@rel='stylesheet']/@href"
|
119
|
-
|
120
|
-
hrefs.class # => Nokogiri::XML::NodeSet
|
121
|
-
href = hrefs.first.value # => "https://static.xx.fbcdn.net/rsrc.php/v3/y1/l/0,cross/NvZ4mNTW3Fd.css"
|
122
|
-
|
123
|
-
css = crawler.crawl href.to_url
|
124
|
-
css[0..50] # => "._3_s0._3_s0{border:0;display:flex;height:44px;min-"
|
125
|
-
```
|
126
|
-
|
127
|
-
### Keyword Indexer (SEO Helper)
|
128
|
-
|
129
|
-
The below script downloads the contents of several webpages and pulls out their keywords for comparison. Such a script might be used by marketeers for search engine optimisation for example.
|
130
|
-
|
131
|
-
```ruby
|
132
|
-
require 'wgit'
|
133
|
-
|
134
|
-
my_pages_keywords = ["Everest", "mountaineering school", "adventure"]
|
135
|
-
my_pages_missing_keywords = []
|
136
|
-
|
137
|
-
competitor_urls = [
|
138
|
-
"http://altitudejunkies.com",
|
139
|
-
"http://www.mountainmadness.com",
|
140
|
-
"http://www.adventureconsultants.com"
|
141
|
-
]
|
142
|
-
|
143
|
-
crawler = Wgit::Crawler.new competitor_urls
|
144
|
-
|
145
|
-
crawler.crawl do |doc|
|
146
|
-
# If there are keywords present in the web document.
|
147
|
-
if doc.keywords.respond_to? :-
|
148
|
-
puts "The keywords for #{doc.url} are: \n#{doc.keywords}\n\n"
|
149
|
-
my_pages_missing_keywords.concat(doc.keywords - my_pages_keywords)
|
150
|
-
end
|
151
|
-
end
|
152
|
-
|
153
|
-
if my_pages_missing_keywords.empty?
|
154
|
-
puts "Your pages are missing no keywords, nice one!"
|
155
|
-
else
|
156
|
-
puts "Your pages compared to your competitors are missing the following keywords:"
|
157
|
-
puts my_pages_missing_keywords.uniq
|
158
|
-
end
|
159
|
-
```
|
160
|
-
|
161
|
-
## Practical Database Example
|
162
|
-
|
163
|
-
This next example requires a configured database instance. Currently the only supported DBMS is MongoDB. See [MongoDB Atlas](https://www.mongodb.com/cloud/atlas) for a free (small) account or provide your own MongoDB instance.
|
164
|
-
|
165
|
-
`Wgit::Database` provides a light wrapper of logic around the `mongo` gem allowing for simple database interactivity and serialisation. With Wgit you can index webpages, store them in a database and then search through all that's been indexed. The use of a database is entirely optional however and isn't required for crawling/indexing.
|
166
|
-
|
167
|
-
The following versions of MongoDB are supported:
|
168
|
-
|
169
|
-
| Gem | Database |
|
170
|
-
| ------ | -------- |
|
171
|
-
| ~> 2.9 | ~> 4.0 |
|
172
|
-
|
173
|
-
### Setting Up MongoDB
|
174
|
-
|
175
|
-
Follow the steps below to configure MongoDB for use with Wgit. This is only needed if you want to read/write database records.
|
176
|
-
|
177
|
-
1) Create collections for: `documents` and `urls`.
|
178
|
-
2) Add a [*unique index*](https://docs.mongodb.com/manual/core/index-unique/) for the `url` field in **both** collections.
|
179
|
-
3) Enable `textSearchEnabled` in MongoDB's configuration (if not already so).
|
180
|
-
4) Create a [*text search index*](https://docs.mongodb.com/manual/core/index-text/#index-feature-text) for the `documents` collection using:
|
181
|
-
```json
|
182
|
-
{
|
183
|
-
"text": "text",
|
184
|
-
"author": "text",
|
185
|
-
"keywords": "text",
|
186
|
-
"title": "text"
|
187
|
-
}
|
188
|
-
```
|
189
|
-
5) Set the connection details for your MongoDB instance (see below) using `Wgit.set_connection_details` (prior to calling `Wgit::Database#new`)
|
190
|
-
|
191
|
-
**Note**: The *text search index* (in step 4) lists all document fields to be searched by MongoDB when calling `Wgit::Database#search`. Therefore, you should append this list with any other fields that you want searched. For example, if you [extend the API](#Extending-The-API) then you might want to search your new fields in the database by adding them to the index above.
|
192
|
-
|
193
|
-
### Database Example
|
194
|
-
|
195
|
-
The below script shows how to use Wgit's database functionality to index and then search HTML documents stored in the database. If you're running the code for yourself, remember to replace the database [connection string](https://docs.mongodb.com/manual/reference/connection-string/) with your own.
|
196
|
-
|
197
|
-
```ruby
|
198
|
-
require 'wgit'
|
199
|
-
require 'wgit/core_ext' # => Provides the String#to_url and Enumerable#to_urls methods.
|
200
|
-
|
201
|
-
### CONNECT TO THE DATABASE ###
|
202
|
-
|
203
|
-
# Set your connection details manually (as below) or from the environment using
|
204
|
-
# Wgit.set_connection_details_from_env
|
205
|
-
Wgit.set_connection_details('DB_CONNECTION_STRING' => '<your_connection_string>')
|
206
|
-
db = Wgit::Database.new # Connects to the database...
|
207
|
-
|
208
|
-
### SEED SOME DATA ###
|
209
|
-
|
210
|
-
# Here we create our own document rather than crawling the web (which works in the same way).
|
211
|
-
# We pass the web page's URL and HTML Strings.
|
212
|
-
doc = Wgit::Document.new(
|
213
|
-
"http://test-url.com".to_url,
|
214
|
-
"<html><p>How now brown cow.</p><a href='http://www.google.co.uk'>Click me!</a></html>"
|
215
|
-
)
|
216
|
-
db.insert doc
|
217
|
-
|
218
|
-
### SEARCH THE DATABASE ###
|
219
|
-
|
220
|
-
# Searching the database returns Wgit::Document's which have fields containing the query.
|
221
|
-
query = "cow"
|
222
|
-
results = db.search query
|
223
|
-
|
224
|
-
search_result = results.first
|
225
|
-
search_result.class # => Wgit::Document
|
226
|
-
doc.url == search_result.url # => true
|
227
|
-
|
228
|
-
### PULL OUT THE BITS THAT MATCHED OUR QUERY ###
|
229
|
-
|
230
|
-
# Searching the returned documents gives the matching text from that document.
|
231
|
-
search_result.search(query).first # => "How now brown cow."
|
232
|
-
|
233
|
-
### SEED URLS TO BE CRAWLED LATER ###
|
234
|
-
|
235
|
-
db.insert search_result.external_links
|
236
|
-
urls_to_crawl = db.uncrawled_urls # => Results will include search_result.external_links.
|
237
|
-
```
|
238
|
-
|
239
|
-
## Extending The API
|
240
|
-
|
241
|
-
Indexing in Wgit is the means of downloading a web page and serialising parts of the content into accessible document attributes/methods. For example, `Wgit::Document#author` will return you the webpage's HTML tag value of `meta[@name='author']`.
|
242
|
-
|
243
|
-
By default, Wgit indexes what it thinks are the most important pieces of information from each webpage. This of course is often not enough given the nature of webpages and their differences from each other. Therefore, there exists a set of ways to extend the default indexing logic.
|
244
|
-
|
245
|
-
There are two ways to extend the indexing behaviour of Wgit:
|
246
|
-
|
247
|
-
1. Add the elements containing **text** that you're interested in to be indexed.
|
248
|
-
2. Define custom indexers matched to specific **elements** that you're interested in.
|
249
|
-
|
250
|
-
Below describes these two methods in more detail.
|
251
|
-
|
252
|
-
### 1. Extending The Default Text Elements
|
253
|
-
|
254
|
-
Wgit contains an array of `Wgit::Document.text_elements` which are the default set of webpage elements containing text; which in turn are indexed and accessible via `Wgit::Document#text`.
|
255
|
-
|
256
|
-
If you'd like the text of additional webpage elements to be returned from `Wgit::Document#text`, then you can do the following:
|
257
|
-
|
258
|
-
```ruby
|
259
|
-
require 'wgit'
|
260
|
-
require 'wgit/core_ext'
|
261
|
-
|
262
|
-
# Let's add the text of links e.g. <a> tags.
|
263
|
-
Wgit::Document.text_elements << :a
|
264
|
-
|
265
|
-
# Our Document has a link whose's text we're interested in.
|
266
|
-
doc = Wgit::Document.new(
|
267
|
-
"http://some_url.com".to_url,
|
268
|
-
"<html><p>Hello world!</p>\
|
269
|
-
<a href='https://made-up-link.com'>Click this link.</a></html>"
|
270
|
-
)
|
271
|
-
|
272
|
-
# Now all crawled Documents will contain all visible link text in Wgit::Document#text.
|
273
|
-
doc.text # => ["Hello world!", "Click this link."]
|
274
|
-
```
|
275
|
-
|
276
|
-
**Note**: This only works for textual page content. For more control over the indexed elements themselves, see below.
|
277
|
-
|
278
|
-
### 2. Defining Custom Indexers Via Document Extensions
|
279
|
-
|
280
|
-
If you want full control over the elements being indexed for your own purposes, then you can define a custom indexer for each type of element that you're interested in.
|
281
|
-
|
282
|
-
Once you have the indexed page element, accessed via a `Wgit::Document` instance method, you can do with it as you wish e.g. obtain it's text value or manipulate the element etc. Since the returned types are plain [Nokogiri](https://www.rubydoc.info/github/sparklemotion/nokogiri) objects, you have the full control that the Nokogiri gem gives you.
|
283
|
-
|
284
|
-
Here's how to add a Document extension to index a specific page element:
|
285
|
-
|
286
|
-
```ruby
|
287
|
-
require 'wgit'
|
288
|
-
require 'wgit/core_ext'
|
289
|
-
|
290
|
-
# Let's get all the page's table elements.
|
291
|
-
Wgit::Document.define_extension(
|
292
|
-
:tables, # Wgit::Document#tables will return the page's tables.
|
293
|
-
"//table", # The xpath to extract the tables.
|
294
|
-
singleton: false, # True returns the first table found, false returns all.
|
295
|
-
text_content_only: false, # True returns one or more Strings of the tables text,
|
296
|
-
# false returns the tables as Nokogiri objects (see below).
|
297
|
-
) do |tables|
|
298
|
-
# Here we can manipulate the object(s) before they're set as Wgit::Document#tables.
|
299
|
-
end
|
300
|
-
|
301
|
-
# Our Document has a table which we're interested in.
|
302
|
-
doc = Wgit::Document.new(
|
303
|
-
"http://some_url.com".to_url,
|
304
|
-
"<html><p>Hello world!</p>\
|
305
|
-
<table><th>Header Text</th><th>Another Header</th></table></html>"
|
306
|
-
)
|
307
|
-
|
308
|
-
# Call our newly defined method to obtain the table data we're interested in.
|
309
|
-
tables = doc.tables
|
310
|
-
|
311
|
-
# Both the collection and each table within the collection are plain Nokogiri objects.
|
312
|
-
tables.class # => Nokogiri::XML::NodeSet
|
313
|
-
tables.first.class # => Nokogiri::XML::Element
|
314
|
-
```
|
315
|
-
|
316
|
-
**Note**: Wgit uses Document extensions to provide much of it's core functionality, providing access to a webpages text or links for example. These [default Document extensions](https://github.com/michaeltelford/wgit/blob/master/lib/wgit/document_extensions.rb) provide examples for your own.
|
317
|
-
|
318
|
-
**Extension Notes**:
|
319
|
-
|
320
|
-
- Any page links should be mapped into `Wgit::Url` objects; Url's are treated as Strings when being inserted into the database.
|
321
|
-
- Any object (like a Nokogiri object) will not be inserted into the database, it's up to you to map each object into a primitive type e.g. `Boolean, Array` etc.
|
322
|
-
|
323
|
-
## Caveats
|
324
|
-
|
325
|
-
Below are some points to keep in mind when using Wgit:
|
326
|
-
|
327
|
-
- All absolute `Wgit::Url`'s must be prefixed with an appropiate protocol e.g. `https://` etc.
|
328
|
-
- By default, up to 5 URL redirects will be followed; this is configurable however.
|
329
|
-
- IRI's (URL's containing non ASCII characters) are supported and will be normalised/escaped prior to being crawled.
|
330
|
-
|
331
|
-
## Executable
|
332
|
-
|
333
|
-
Currently there is no executable provided with Wgit, however...
|
334
|
-
|
335
|
-
In future versions of Wgit, an executable will be packaged with the gem. The executable will provide a `pry` console with the `wgit` gem already loaded. Using the console, you'll easily be able to index and search the web without having to write your own scripts.
|
336
|
-
|
337
|
-
This executable will be similar in nature to `./bin/console` which is currently used for development and isn't packaged as part of the `wgit` gem.
|
338
|
-
|
339
|
-
## Change Log
|
340
|
-
|
341
|
-
See the [CHANGELOG.md](https://github.com/michaeltelford/wgit/blob/master/CHANGELOG.md) for differences (including any breaking changes) between releases of Wgit.
|
342
|
-
|
343
|
-
## License
|
344
|
-
|
345
|
-
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
346
|
-
|
347
|
-
## Contributing
|
348
|
-
|
349
|
-
Bug reports and feature requests are welcome on [GitHub](https://github.com/michaeltelford/wgit/issues). Just raise an issue, checking it doesn't already exist.
|
350
|
-
|
351
|
-
The current road map is rudimentally listed in the [TODO.txt](https://github.com/michaeltelford/wgit/blob/master/TODO.txt) file. Maybe your feature request is already there?
|
352
|
-
|
353
|
-
## Development
|
354
|
-
|
355
|
-
For a full list of available Rake tasks, run `bundle exec rake help`. The most commonly used tasks are listed below...
|
356
|
-
|
357
|
-
After checking out the repo, run `bundle exec rake setup` to install the dependencies (requires `bundler`). Then, run `bundle exec rake test` to run the tests. You can also run `bundle exec rake console` for an interactive (`pry`) REPL that will allow you to experiment with the code.
|
358
|
-
|
359
|
-
To generate code documentation run `bundle exec yardoc`. To browse the generated documentation run `bundle exec yard server -r`.
|
360
|
-
|
361
|
-
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, see the *Gem Publishing Checklist* section of the `TODO.txt` file.
|
data/TODO.txt
DELETED
@@ -1,34 +0,0 @@
|
|
1
|
-
|
2
|
-
Primary
|
3
|
-
-------
|
4
|
-
- Update Database#search & Document#search to have optional case sensitivity.
|
5
|
-
- Have the ability to crawl sub sections of a site only e.g. https://www.honda.co.uk/motorcycles.html as the base url and crawl any links containing this as a prefix. For example, https://www.honda.co.uk/cars.html would not be crawled but https://www.honda.co.uk/motorcycles/africa-twin.html would be.
|
6
|
-
- Create an executable based on the ./bin/console shipped as `wpry` or `wgit`.
|
7
|
-
|
8
|
-
Secondary
|
9
|
-
---------
|
10
|
-
- Think about how we handle invalid Url's on crawled documents. Setup tests and implement logic for this scenario.
|
11
|
-
- Check if Document::TEXT_ELEMENTS is expansive enough.
|
12
|
-
|
13
|
-
Refactoring
|
14
|
-
-----------
|
15
|
-
- Plan to open up the required_ruby_version range, say from 2.5 upwards e.g. `~> 2.5`. Will need CI testing for the different versions of ruby as we move onto support newer versions.
|
16
|
-
- Refactor the 3 main classes and their tests (where needed): Url, Document & Crawler.
|
17
|
-
- After the above refactor, move onto the rest of the code base.
|
18
|
-
- Think about reducing the amount of method aliases, pick the best for the method def and remove the aliases? Also, do the Url#to_* make sense?
|
19
|
-
- Replace method params with named parameters where applicable.
|
20
|
-
- Possibly use refine instead of core-ext?
|
21
|
-
- Think about potentially using DB._update's update_many func.
|
22
|
-
|
23
|
-
Gem Publishing Checklist
|
24
|
-
------------------------
|
25
|
-
- Ensure a clean branch of master and create a 'release' branch.
|
26
|
-
- Update standalone files (if necessary): README.md, TODO.txt, wgit.gemspec etc.
|
27
|
-
- Increment the version number (in version.rb) and update the CHANGELOG.md.
|
28
|
-
- Run 'bundle install' to update deps.
|
29
|
-
- Run 'bundle exec rake compile' and ensure acceptable warnings.
|
30
|
-
- Run 'bundle exec rake test' and ensure all tests are passing.
|
31
|
-
- Run `bundle exec rake install` to build and install the gem locally, then test it manually from outside this repo.
|
32
|
-
- Run `bundle exec yardoc` to update documentation - should be 100% coverage.
|
33
|
-
- Commit, merge to master & push any changes made from the above steps.
|
34
|
-
- Run `bundle exec rake RELEASE[origin]` to tag, build and push everything to github.com and rubygems.org.
|
@@ -1,41 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require_relative '../assertable'
|
4
|
-
|
5
|
-
module Wgit
|
6
|
-
extend Assertable
|
7
|
-
|
8
|
-
# The connection details for the database. This must be set if you want to
|
9
|
-
# store and access webpages in a database. Don't set the constant directly,
|
10
|
-
# instead use the funcs contained within the Wgit module.
|
11
|
-
CONNECTION_DETAILS = {}
|
12
|
-
|
13
|
-
# The keys required for a successful database connection.
|
14
|
-
CONNECTION_KEYS_REQUIRED = ['DB_CONNECTION_STRING'].freeze
|
15
|
-
|
16
|
-
# Set the database's connection details from the given hash. It is your
|
17
|
-
# responsibility to ensure the correct hash vars are present and set.
|
18
|
-
#
|
19
|
-
# @param hash [Hash] Containing the database connection details to use.
|
20
|
-
# The hash should contain the following keys (of type String):
|
21
|
-
# DB_CONNECTION_STRING
|
22
|
-
# @raise [KeyError] If any of the required connection details are missing.
|
23
|
-
# @return [Hash] Containing the database connection details from hash.
|
24
|
-
def self.set_connection_details(hash)
|
25
|
-
assert_required_keys(hash, CONNECTION_KEYS_REQUIRED)
|
26
|
-
CONNECTION_DETAILS[:connection_string] = hash.fetch('DB_CONNECTION_STRING')
|
27
|
-
CONNECTION_DETAILS
|
28
|
-
end
|
29
|
-
|
30
|
-
# Set the database's connection details from the ENV. It is your
|
31
|
-
# responsibility to ensure the correct ENV vars are present and set.
|
32
|
-
#
|
33
|
-
# The ENV should contain the following keys (of type String):
|
34
|
-
# DB_CONNECTION_STRING
|
35
|
-
#
|
36
|
-
# @raise [KeyError] If any of the required connection details are missing.
|
37
|
-
# @return [Hash] Containing the database connection details from the ENV.
|
38
|
-
def self.set_connection_details_from_env
|
39
|
-
set_connection_details(ENV)
|
40
|
-
end
|
41
|
-
end
|