module GutenbergBookFinder

Constants

VERSION

Public Class Methods

book_info(id) click to toggle source
# 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) click to toggle source
# 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() click to toggle source
# 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