Class: OAI::Provider::Metadata::Format
- Inherits:
-
Object
- Object
- OAI::Provider::Metadata::Format
- Includes:
- Singleton
- Defined in:
- lib/oai/provider/metadata_format.rb
Overview
Metadata Base Class
MetadataFormat is the base class from which all other format classes should inherit. Format classes provide mapping of record fields into XML.
-
prefix - contains the metadata_prefix used to select the format
-
schema - location of the xml schema
-
namespace - location of the namespace document
-
element_namespace - the namespace portion of the XML elements
-
fields - list of fields in this metadata format
See OAI::Metadata::DublinCore for an example
Direct Known Subclasses
Instance Attribute Summary collapse
-
#element_namespace ⇒ Object
Returns the value of attribute element_namespace.
-
#fields ⇒ Object
Returns the value of attribute fields.
-
#namespace ⇒ Object
Returns the value of attribute namespace.
-
#prefix ⇒ Object
Returns the value of attribute prefix.
-
#schema ⇒ Object
Returns the value of attribute schema.
Instance Method Summary collapse
-
#encode(model, record) ⇒ Object
Provided a model, and a record belonging to that model this method will return an xml represention of the record.
Instance Attribute Details
#element_namespace ⇒ Object
Returns the value of attribute element_namespace.
20 21 22 |
# File 'lib/oai/provider/metadata_format.rb', line 20 def element_namespace @element_namespace end |
#fields ⇒ Object
Returns the value of attribute fields.
20 21 22 |
# File 'lib/oai/provider/metadata_format.rb', line 20 def fields @fields end |
#namespace ⇒ Object
Returns the value of attribute namespace.
20 21 22 |
# File 'lib/oai/provider/metadata_format.rb', line 20 def namespace @namespace end |
#prefix ⇒ Object
Returns the value of attribute prefix.
20 21 22 |
# File 'lib/oai/provider/metadata_format.rb', line 20 def prefix @prefix end |
#schema ⇒ Object
Returns the value of attribute schema.
20 21 22 |
# File 'lib/oai/provider/metadata_format.rb', line 20 def schema @schema end |
Instance Method Details
#encode(model, record) ⇒ Object
Provided a model, and a record belonging to that model this method will return an xml represention of the record. This is the method that should be extended if you need to create more complex xml representations.
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/oai/provider/metadata_format.rb', line 26 def encode(model, record) if record.respond_to?("to_#{prefix}") record.send("to_#{prefix}") else xml = Builder::XmlMarkup.new map = model.respond_to?("map_#{prefix}") ? model.send("map_#{prefix}") : {} xml.tag!("#{prefix}:#{element_namespace}", header_specification) do if fields.is_a?(Array) fields.each do |field| values = value_for(field, record, map) if values.respond_to?(:each) values.each do |value| xml.tag! "#{element_namespace}:#{field}", value end else xml.tag! "#{element_namespace}:#{field}", values end end elsif fields.is_a?(Hash) fields.each_pair do |key, field_array| field_array.to_a.each do |field| values = value_for(field, record, map) if values.respond_to?(:each) values.each do |value| xml.tag! "#{key}:#{field}", value end else xml.tag! "#{key}:#{field}", values end end end end end xml.target! end end |