Class: ActiveFedora::SolrHit

Inherits:
Delegator
  • Object
show all
Defined in:
lib/active_fedora/solr_hit.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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

#documentObject (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

#idObject



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

Returns:

  • (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_uriObject



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