Skip to content

Instantly share code, notes, and snippets.

@radar
Created July 15, 2011 12:11
Show Gist options
  • Save radar/1084579 to your computer and use it in GitHub Desktop.
Save radar/1084579 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| chapter.elements.process!(element) }
end
class Element
include Mongoid::Document
extend 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?
#######################
[[[???]]].elements.send("process_#{markup.name}!", markup)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment