Class: TaliaCore::Oai::ActiveSourceOaiAdapter
- Extended by:
- OaiAdapterClassMethods
- Defined in:
- lib/talia_core/oai/active_source_oai_adapter.rb
Overview
Wraps an ActiveSource record so that it provides the accessor methods for DublinCore. In a nutshell, this makes the object look like an ActiveRecord with “fields” like “title” or “subject”. The OAI provider can access those fields to automatically read the metatdata from the records.
Wrapping an ActiveSource
Use ActiveSourceOaiAdapter.get_wrapper_for(record) to create a new wrapper object for a given ActiveSource. Usually the ActiveSourceModel will do this automatically.
Extending the adapter
If you need more specific functionality, you may subclass the adapter or write your own adapter class that includes OaiAdapterClassMethods
In both cases you’ll get the #namespace_field class method - this will allow you to define accessors to properties in the following way:
# This maps the dcns:title and dcns:foo properties on the original
# source to the #title and #foo accessors
namespace_field :dcns, :title, :foo
Class Method Summary collapse
-
.get_wrapper_for(records) ⇒ Object
Tries to instanciate a wrapper object for the record, using the wrapper class that corresponds to the given record’s class.
Instance Method Summary collapse
-
#created_at ⇒ Object
Timestamp for the record.
-
#creator ⇒ Object
Get the author/creator.
-
#id ⇒ Object
Id for the record.
-
#identifier ⇒ Object
Identifier for the resource.
-
#initialize(record) ⇒ ActiveSourceOaiAdapter
constructor
A new instance of ActiveSourceOaiAdapter.
-
#type ⇒ Object
Type information.
Methods included from OaiAdapterClassMethods
Constructor Details
#initialize(record) ⇒ ActiveSourceOaiAdapter
Returns a new instance of ActiveSourceOaiAdapter.
51 52 53 54 |
# File 'lib/talia_core/oai/active_source_oai_adapter.rb', line 51 def initialize(record) assit_kind_of(ActiveSource, record) @record = record end |
Class Method Details
.get_wrapper_for(records) ⇒ Object
Tries to instanciate a wrapper object for the record, using the wrapper class that corresponds to the given record’s class
91 92 93 94 95 96 97 98 99 100 101 |
# File 'lib/talia_core/oai/active_source_oai_adapter.rb', line 91 def self.get_wrapper_for(records) if(records.is_a?(ActiveSource)) self.new(records) elsif(records.respond_to?(:collect)) records.collect { |rec| self.new(rec) } elsif(records.nil?) nil else raise(ArgumentError, "Don't know how to wrap #{records.inspect}") end end |
Instance Method Details
#created_at ⇒ Object
Timestamp for the record
80 81 82 |
# File 'lib/talia_core/oai/active_source_oai_adapter.rb', line 80 def created_at @record.created_at end |
#creator ⇒ Object
Get the author/creator
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/talia_core/oai/active_source_oai_adapter.rb', line 57 def creator @record[N::DCNS.creator].collect do |creator| creator # if(creator.is_a?(TaliaCore::ActiveSource)) # author = '' # author_name = creator.hyper::author_name.first # author << author_name << ' ' if(author_name) # author_surname = creator.hyper::author_surname.first || '' # author << author_surname if(author_surname) # author = "No lookup. Author should be at #{creator.uri}" if(author == '') # author # else # creator # end end end |
#id ⇒ Object
Id for the record
85 86 87 |
# File 'lib/talia_core/oai/active_source_oai_adapter.rb', line 85 def id @record.id end |
#identifier ⇒ Object
Identifier for the resource
75 76 77 |
# File 'lib/talia_core/oai/active_source_oai_adapter.rb', line 75 def identifier @record.uri.to_s end |
#type ⇒ Object
Type information. Base class is not terribly useful, but needed to overwrite default #type method
47 48 49 |
# File 'lib/talia_core/oai/active_source_oai_adapter.rb', line 47 def type '' end |