Sha256: 48a87d58a9f8672b752c2bbfe4d1b45db5276e77151ae64c92dc13cb3b1b29e1
Contents?: true
Size: 1.18 KB
Versions: 1
Compression:
Stored size: 1.18 KB
Contents
module GoogleApps class DocumentHandler def initialize @documents = look_up_doc_types end # create_doc creates a document of the specified format # from the given string. def create_doc(text, type = nil) @documents.include?(type) ? doc_of_type(text, type) : unknown_type(text) end # unknown_type takes a string and returns a document of # of the corresponding @format. def unknown_type(text) Atom::XML::Document.string(text) end # doc_of_type takes a document type and a string and # returns a document of that type in the current format. def doc_of_type(text, type) raise "No Atom document of type: #{type}" unless @documents.include?(type.to_s) GoogleApps::Atom.send(type, text) end private # look_up_doc_types returns a list of document types the # library supports in the current format. def look_up_doc_types Atom::Document.types.map { |subclass| sub_to_meth(subclass) } end def sub_to_meth(subclass) # TODO: This shouldn't be both here and in GoogleApps::Atom::Document subclass.to_s.split('::').last.scan(/[A-Z][a-z0-9]+/).map(&:downcase).join('_') end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
google_apps-0.9 | lib/google_apps/document_handler.rb |