Class: ActiveFedora::SolrDigitalObject

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(solr_doc, profile_hash, klass = ActiveFedora::Base) ⇒ SolrDigitalObject

Returns a new instance of SolrDigitalObject.



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/active_fedora/solr_digital_object.rb', line 5

def initialize(solr_doc, profile_hash, klass=ActiveFedora::Base)
  @solr_doc = solr_doc
  @pid = solr_doc[SOLR_DOCUMENT_ID]
  @profile = {}
  profile_hash.each_pair { |key,value| @profile[key] = value.to_s if key =~ /^obj/ }
  @profile['objCreateDate'] ||= Time.now.xmlschema
  @profile['objLastModDate'] ||= @profile['objCreateDate']

  @datastreams = {}
  
  dsids = profile_hash['datastreams'].keys
  missing = dsids - klass.ds_specs.keys
  missing.each do |dsid|
    #Initialize the datastreams that are in the solr document, but not found in the classes spec.
    mime_type = profile_hash['datastreams'][dsid]['dsMIME']
    ds_class = mime_type =~ /[\/\+]xml$/ ? NokogiriDatastream : Datastream
    @datastreams[dsid] = ds_class.new(self, dsid)
  end

  @label = @profile['objLabel']
  @state = @profile['objState']
  @ownerId = @profile['objOwnerId']
end

Instance Attribute Details

#datastreamsObject (readonly)

Returns the value of attribute datastreams.



3
4
5
# File 'lib/active_fedora/solr_digital_object.rb', line 3

def datastreams
  @datastreams
end

#labelObject (readonly)

Returns the value of attribute label.



3
4
5
# File 'lib/active_fedora/solr_digital_object.rb', line 3

def label
  @label
end

#ownerIdObject (readonly)

Returns the value of attribute ownerId.



3
4
5
# File 'lib/active_fedora/solr_digital_object.rb', line 3

def ownerId
  @ownerId
end

#pidObject (readonly)

Returns the value of attribute pid.



3
4
5
# File 'lib/active_fedora/solr_digital_object.rb', line 3

def pid
  @pid
end

#profileObject (readonly)

Returns the value of attribute profile.



3
4
5
# File 'lib/active_fedora/solr_digital_object.rb', line 3

def profile
  @profile
end

#solr_docObject (readonly)

Returns the value of attribute solr_doc.



3
4
5
# File 'lib/active_fedora/solr_digital_object.rb', line 3

def solr_doc
  @solr_doc
end

#stateObject (readonly)

Returns the value of attribute state.



3
4
5
# File 'lib/active_fedora/solr_digital_object.rb', line 3

def state
  @state
end

Instance Method Details

#freezeObject



29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/active_fedora/solr_digital_object.rb', line 29

def freeze
  @finished = true
  @profile.freeze
  @datastreams.freeze
  class << self
    #Once this instance is frozen create a repository method just for this one instance.
    define_method :repository do
      ActiveFedora::Base.connection_for_pid(self.pid)
    end
  end
  self
end

#new?Boolean

Returns:

  • (Boolean)


42
43
44
# File 'lib/active_fedora/solr_digital_object.rb', line 42

def new?
  false
end