-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Anthony Smith
committed
Oct 29, 2013
1 parent
232e08a
commit 4c68b6d
Showing
5 changed files
with
70 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
module ARBookFinder | ||
class CollectionProcessor | ||
include Capybara::DSL | ||
|
||
COLLECTIONS_URL = "#{ARBookFinder::BASE_URL}/collections.aspx" | ||
|
||
def initialize(collections) | ||
@collections = collections | ||
end | ||
|
||
def process | ||
unless current_url.downcase == COLLECTIONS_URL | ||
visit(COLLECTIONS_URL) | ||
end | ||
navigate_collection(@collections) | ||
end | ||
|
||
private | ||
def navigate_collection(collection) | ||
collection.each do |key, value| | ||
click_on(key) | ||
if value.kind_of?(Hash) | ||
navigate_collection(value) | ||
else | ||
click_on(value) | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,17 @@ | ||
module ARBookFinder | ||
class Scraper | ||
def initialize(user_type) | ||
@user_type = user_type | ||
UserTypeProcessor.new(user_type).process | ||
end | ||
|
||
def search(query, page = 1, sort_by = 'Relevance') | ||
UserTypeProcessor.new(@user_type).process | ||
QuickSearchProcessor.new(query, page, sort_by).process | ||
SearchResultsParser.new(Capybara.page.html).parse | ||
end | ||
|
||
def collection(collection) | ||
CollectionProcessor.new(collection).process | ||
SearchResultsParser.new(Capybara.page.html, true).parse | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
require 'spec_helper' | ||
|
||
describe 'Collection' do | ||
it 'should return results for a single child hash' do | ||
results = ARBookFinder.collection('Awards' => 'ALA Notable/Best Books') | ||
results.books.size.should > 0 | ||
end | ||
|
||
it 'should return results for a multi child hash' do | ||
results = ARBookFinder.collection('State Lists' => { 'Indiana' => 'IN Young Hoosier Middle Grades Book Award Nominees 2013-2014' }) | ||
results.books.size.should > 0 | ||
end | ||
|
||
it 'should fetch book data' do | ||
results = ARBookFinder.collection('Awards' => 'ALA Notable/Best Books') | ||
book = results.books[0] | ||
book.fetch | ||
book.title.should_not be '' | ||
end | ||
end |