Class: ActiveFedora::SolrHit
- Inherits:
-
Delegator
- Object
- Delegator
- ActiveFedora::SolrHit
- Defined in:
- lib/active_fedora/solr_hit.rb
Instance Attribute Summary collapse
-
#document ⇒ Object
readonly
Returns the value of attribute document.
Class Method Summary collapse
Instance Method Summary collapse
- #__getobj__ ⇒ Object (also: #static_config)
- #__setobj__(obj) ⇒ Object
- #id ⇒ Object
-
#initialize(document) ⇒ SolrHit
constructor
A new instance of SolrHit.
- #model(opts = {}) ⇒ Object
- #model?(model_to_check) ⇒ Boolean
- #rdf_uri ⇒ Object
- #reify(opts = {}) ⇒ Object
Constructor Details
#initialize(document) ⇒ SolrHit
Returns a new instance of SolrHit.
23 24 25 26 27 |
# File 'lib/active_fedora/solr_hit.rb', line 23 def initialize(document) document = document.with_indifferent_access super @document = document end |
Instance Attribute Details
#document ⇒ Object (readonly)
Returns the value of attribute document.
21 22 23 |
# File 'lib/active_fedora/solr_hit.rb', line 21 def document @document end |
Class Method Details
.for(hit) ⇒ Object
3 4 5 6 7 |
# File 'lib/active_fedora/solr_hit.rb', line 3 def self.for(hit) return hit if hit.is_a? ActiveFedora::SolrHit SolrHit.new(hit) end |
Instance Method Details
#__getobj__ ⇒ Object Also known as: static_config
11 12 13 |
# File 'lib/active_fedora/solr_hit.rb', line 11 def __getobj__ @document # return object we are delegating to, required end |
#__setobj__(obj) ⇒ Object
17 18 19 |
# File 'lib/active_fedora/solr_hit.rb', line 17 def __setobj__(obj) @document = obj end |
#id ⇒ Object
29 30 31 |
# File 'lib/active_fedora/solr_hit.rb', line 29 def id document[ActiveFedora.id_field] end |
#model(opts = {}) ⇒ Object
37 38 39 40 41 |
# File 'lib/active_fedora/solr_hit.rb', line 37 def model(opts = {}) best_model_match = classifier.best_model(opts) ActiveFedora::Base.logger.warn "Could not find a model for #{id}, defaulting to ActiveFedora::Base" if best_model_match == ActiveFedora::Base best_model_match end |
#model?(model_to_check) ⇒ Boolean
43 44 45 46 47 |
# File 'lib/active_fedora/solr_hit.rb', line 43 def model?(model_to_check) models.any? do |model| model_to_check >= model end end |
#rdf_uri ⇒ Object
33 34 35 |
# File 'lib/active_fedora/solr_hit.rb', line 33 def rdf_uri ::RDF::URI.new(ActiveFedora::Base.id_to_uri(id)) end |
#reify(opts = {}) ⇒ Object
49 50 51 |
# File 'lib/active_fedora/solr_hit.rb', line 49 def reify(opts = {}) model(opts).find(id, cast: true) end |