Skip to content

Instantly share code, notes, and snippets.

@localshred
Created April 21, 2010 20:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save localshred/374369 to your computer and use it in GitHub Desktop.
Save localshred/374369 to your computer and use it in GitHub Desktop.
book_names.each do |book_title|
chapters = agent.page.links_with(:href => book_title)
chapter_id = 0
chapters.each do |ch|
chapter_id += 1
ch.click
content = agent.page.search(".result-text-style-normal").map(&:text).map(&:strip).to_s
passage_text = Passager.new(content, 0)
passage_text.passages.each do |p|
Verse.create!(:body => p, :chapter_id => chapter_id)
end
back = agent.page.link_with(:href => /New\-King\-James/)
back.click
end
end
book_names.each do |book_title|
book_record = Book.create(:title => book_title)
chapters = agent.page.links_with(:href => book_title)
chapters.each do |ch|
chapter_title = agent.page.search("h1#chapter-name")
chapter_record = Chapter.create(:title => chapter_title, :book => book_record)
ch.click
content = agent.page.search(".result-text-style-normal").map(&:text).map(&:strip).to_s
passage_text = Passager.new(content, 0)
passage_text.passages.each do |p|
Verse.create!(:body => p, :chapter => chapter_record)
end
back = agent.page.link_with(:href => /New\-King\-James/)
back.click
end
end
class Book < ActiveRecord::Base
has_many :chapters
end
class Chapter < ActiveRecord::Base
belongs_to :book
has_many :verses
end
class Verse < ActiveRecord::Base
belongs_to :chapter
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment