Skip to content

Instantly share code, notes, and snippets.

@lenary
Forked from radar/chapter.rb
Created July 15, 2011 12:25
Show Gist options
  • Save lenary/1084597 to your computer and use it in GitHub Desktop.
Save lenary/1084597 to your computer and use it in GitHub Desktop.
class Chapter
include Mongoid::Document
field :position, :type => Integer
field :title, :type => String
field :identifier, :type => String
embedded_in :book
embeds_many :elements
def self.process!(git, file)
chapter = new
# Parsing of XML goes here, generating parsed_doc
elements = parsed_doc.css("div.chapter > *")
elements.each { |element| element.process! }
end
class Element
include Mongoid::Document
include Processor
field :tag, :type => String
field :identifier, :type => String
field :title, :type => String
embedded_in :chapter
end
module Processor
def process!(markup)
#######################
# How do I gain access to the chapter object these elements are being created from here?
#######################
send("process_#{markup.name}!")
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment