Module: GutenbergBookFinder
- Defined in:
- lib/gutenberg_book_finder.rb,
lib/gutenberg_book_finder/version.rb
Defined Under Namespace
Classes: HtmlParserIncluded, Page
Constant Summary
collapse
- VERSION =
"0.0.2"
Class Method Summary
collapse
Class Method Details
.book_info(id) ⇒ Object
23
24
25
26
27
|
# File 'lib/gutenberg_book_finder.rb', line 23
def self.book_info(id)
page = Page.get "http://www.gutenberg.org/ebooks/#{id}"
info = a.css('#content .header h1').text
title, author = info.split(' by ')
end
|
.book_text(id) ⇒ Object
29
30
31
32
|
# File 'lib/gutenberg_book_finder.rb', line 29
def self.book_text(id)
text_url = "http://www.gutenberg.org/cache/epub/#{id}/pg#{id}.txt"
HTTParty.get(text_url).body
end
|
.random_id ⇒ Object
18
19
20
21
|
# File 'lib/gutenberg_book_finder.rb', line 18
def self.random_id
page = Page.get 'http://www.gutenberg.org/ebooks/search/?sort_order=random'
random_id = page.css('.booklink a.link').first.xpath('@href').to_s.split('/').last.to_i
end
|