Created
December 21, 2011 20:05
-
-
Save jcoyne/1507484 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def self.note_template(opts={}) | |
options = {:text => ""}.merge(opts) | |
builder = Nokogiri::XML::Builder.new do | |
note options[:text], :date=>Time.now.iso8601 | |
end | |
return builder.doc.root | |
end | |
def insert_note(opts={}) | |
node = self.class.note_template(opts) | |
nodeset = self.find_by_terms(:human_review,:field,:note) | |
unless nodeset.nil? | |
if nodeset.empty? | |
review_node = self.find_by_terms(:human_review,:field).first | |
raise "Couldn't find review node" unless review_node | |
review_node.add_child(node) | |
index=0 | |
else | |
nodeset.after(node) | |
index=nodeset.length | |
end | |
self.dirty = true | |
end | |
return node, index | |
end |
Author
jcoyne
commented
Jan 3, 2012
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment