Class: Fedora::FedoraObject

Inherits:
BaseObject show all
Defined in:
lib/fedora/fedora_object.rb

Instance Attribute Summary collapse

Attributes inherited from BaseObject

#attributes, #blob, #errors, #new_object, #url

Instance Method Summary collapse

Methods inherited from BaseObject

#new_object?

Constructor Details

#initialize(attrs = nil) ⇒ FedoraObject

Parameters

attrs<Hash>

fedora object attributes (see below)

Attributes (attrs)

namespace<Symbol>
pid<Symbol>
state<Symbol>
label<Symbol>
contentModel<Symbol>
objectXMLFormat<Symbol>
ownerID<Symbol>

-



20
21
22
23
# File 'lib/fedora/fedora_object.rb', line 20

def initialize(attrs = nil)
  super
  # TODO: check for required attributes
end

Instance Attribute Details

#target_repositoryObject

Returns the value of attribute target_repository.



6
7
8
# File 'lib/fedora/fedora_object.rb', line 6

def target_repository
  @target_repository
end

Instance Method Details

#content_modelObject



80
81
82
# File 'lib/fedora/fedora_object.rb', line 80

def content_model
  self.attributes[:contentModel]
end

#content_model=(new_content_model) ⇒ Object



84
85
86
# File 'lib/fedora/fedora_object.rb', line 84

def content_model=(new_content_model)
  self.attributes[:contentModel] = new_content_model
end

#create_dateObject



43
44
45
# File 'lib/fedora/fedora_object.rb', line 43

def create_date
  objectProfile[:create_date]
end

#labelObject



72
73
74
# File 'lib/fedora/fedora_object.rb', line 72

def label
  self.attributes[:label]
end

#label=(new_label) ⇒ Object



76
77
78
# File 'lib/fedora/fedora_object.rb', line 76

def label=(new_label)
  self.attributes[:label] = new_label
end

#modified_dateObject



47
48
49
# File 'lib/fedora/fedora_object.rb', line 47

def modified_date
  objectProfile[:modified_date]
end

#objectXMLObject



110
111
112
113
# File 'lib/fedora/fedora_object.rb', line 110

def objectXML
  # Use REXML to slurp the attributes (can't use xmlsimple because the XML is too complex.  Need XPath-like queries.
  @objectXML ||= REXML::Document.new(@fedora.call_resource(:retrieve, :objects_objectXml, {:pid => @pid}))
end

#owner_idObject

Get the object and read its @ownerId from the profile



89
90
91
# File 'lib/fedora/fedora_object.rb', line 89

def owner_id
  self.attributes[:ownerID]
end

#owner_id=(new_owner_id) ⇒ Object



93
94
95
# File 'lib/fedora/fedora_object.rb', line 93

def owner_id=(new_owner_id)
  self.attributes.merge!({:ownerID => new_owner_id})
end

#pidObject



52
53
54
# File 'lib/fedora/fedora_object.rb', line 52

def pid
  self.attributes[:pid]
end

#pid=(new_pid) ⇒ Object



56
57
58
# File 'lib/fedora/fedora_object.rb', line 56

def pid=(new_pid)
  self.attributes.merge!({:pid => new_pid})
end

#profileObject



97
98
99
100
101
102
103
104
105
106
107
108
# File 'lib/fedora/fedora_object.rb', line 97

def profile
  # Use xmlsimple to slurp the attributes
  objectProfile = XmlSimple.xml_in(@fedora.call_resource(:retrieve, :objects_profile, {:pid => @pid}))
  # TODO: Find out if xmlsimple automatically expands camelCased element names...
  profile_as_array = {
    :owner_id => objectProfile[objOwnerId],
    :content_model => objectProfile[objContentModel],
    :label => objectProfile[objLabel],
    :date_created => objectProfile[objCreateDate],
    :date_modified => objectProfile[objLastModDate]
  }
end

#retrieve_attr_from_fedoraObject

TODO: Create appropriate attribute accessors for these values.

Where applicable, make sure that attributes are written to and read from self.attributes

pid, label, create_date, modified_date, fedora_object_type, contentModel, state, ownerID, behavior_def, behavior_mech,

API-M Search Value Equivalents: [pid, label, cDate, mDate, fType, cModel, state, ownerId, bDef, bMech,] TODO: Mix In DC attribute finders/accessors TODO: Make sure that fedora_object_type and contentModel are juggled properly.



35
36
37
38
39
40
41
# File 'lib/fedora/fedora_object.rb', line 35

def retrieve_attr_from_fedora
  self.attributes.merge!(objectProfile)
  self.attributes.merge!({
       :state => objectXML.root.elements["objectProperties/property[@NAME='info:fedora/fedora-system:def/model#state']"].attributes["value"]
  })

end

#stateObject



60
61
62
# File 'lib/fedora/fedora_object.rb', line 60

def state
  self.attributes[:state]
end

#state=(new_state) ⇒ Object



64
65
66
67
68
69
70
# File 'lib/fedora/fedora_object.rb', line 64

def state=(new_state)
  if ["I", "A", "D"].include? new_state
    self.attributes[:state]  = new_state
  else
    raise 'The object state of "' + new_state + '" is invalid. The allowed values for state are:  A (active), D (deleted), and I (inactive).'
  end
end

#uriObject



116
117
118
# File 'lib/fedora/fedora_object.rb', line 116

def uri
  "fedora:info/#{pid}"
end