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.4"
Class Method Summary
collapse
Class Method Details
.book_info(id) ⇒ Object
25
26
27
28
29
|
# File 'lib/gutenberg_book_finder.rb', line 25
def self.book_info(id)
page = Page.get "http://www.gutenberg.org/ebooks/#{id}"
info = page.css('#content .header h1').text
title, author = info.split(' by ')
end
|
.book_text(id) ⇒ Object
31
32
33
34
|
# File 'lib/gutenberg_book_finder.rb', line 31
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
20
21
22
23
|
# File 'lib/gutenberg_book_finder.rb', line 20
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
|