Class: ActiveFedora::DefaultModelMapper
- Inherits:
-
Object
- Object
- ActiveFedora::DefaultModelMapper
- Defined in:
- lib/active_fedora/default_model_mapper.rb
Overview
Create model classifiers for resources or solr documents
Instance Attribute Summary collapse
-
#classifier_class ⇒ Object
readonly
Returns the value of attribute classifier_class.
-
#predicate ⇒ Object
readonly
Returns the value of attribute predicate.
-
#solr_field ⇒ Object
readonly
Returns the value of attribute solr_field.
Instance Method Summary collapse
- #classifier(resource) ⇒ Object
-
#initialize(classifier_class: ActiveFedora::ModelClassifier, solr_field: ActiveFedora::QueryResultBuilder::HAS_MODEL_SOLR_FIELD, predicate: ActiveFedora::RDF::Fcrepo::Model.hasModel) ⇒ DefaultModelMapper
constructor
A new instance of DefaultModelMapper.
Constructor Details
#initialize(classifier_class: ActiveFedora::ModelClassifier, solr_field: ActiveFedora::QueryResultBuilder::HAS_MODEL_SOLR_FIELD, predicate: ActiveFedora::RDF::Fcrepo::Model.hasModel) ⇒ DefaultModelMapper
Returns a new instance of DefaultModelMapper.
6 7 8 9 10 |
# File 'lib/active_fedora/default_model_mapper.rb', line 6 def initialize(classifier_class: ActiveFedora::ModelClassifier, solr_field: ActiveFedora::QueryResultBuilder::HAS_MODEL_SOLR_FIELD, predicate: ActiveFedora::RDF::Fcrepo::Model.hasModel) @classifier_class = classifier_class @solr_field = solr_field @predicate = predicate end |
Instance Attribute Details
#classifier_class ⇒ Object (readonly)
Returns the value of attribute classifier_class.
4 5 6 |
# File 'lib/active_fedora/default_model_mapper.rb', line 4 def classifier_class @classifier_class end |
#predicate ⇒ Object (readonly)
Returns the value of attribute predicate.
4 5 6 |
# File 'lib/active_fedora/default_model_mapper.rb', line 4 def predicate @predicate end |
#solr_field ⇒ Object (readonly)
Returns the value of attribute solr_field.
4 5 6 |
# File 'lib/active_fedora/default_model_mapper.rb', line 4 def solr_field @solr_field end |
Instance Method Details
#classifier(resource) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/active_fedora/default_model_mapper.rb', line 12 def classifier(resource) models = if resource.respond_to? :graph resource.graph.query([nil, predicate, nil]).map { |rg| rg.object.to_s } elsif resource.respond_to? :[] resource[solr_field] || [] else [] end classifier_class.new(models) end |