Class: ActiveFedora::Datastream

Inherits:
Rubydora::Datastream
  • Object
show all
Extended by:
Deprecation
Defined in:
lib/active_fedora/datastream.rb

Overview

This class represents a Fedora datastream

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(digital_object = nil, dsid = nil, options = {}) ⇒ Datastream

Returns a new instance of Datastream.

Parameters:

  • digital_object (DigitalObject) (defaults to: nil)

    the digital object that this object belongs to

  • dsid (String) (defaults to: nil)

    the datastream id, if this is nil, a datastream id will be generated.

  • options (Hash) (defaults to: {})

Options Hash (options):

  • :content (String, IO)

    the content for the datastream

  • :dsLabel (String)

    label for the datastream

  • :dsLocation (String)

    location for an external or redirect datastream

  • :controlGroup (String)

    a controlGroup for the datastream

  • :mimeType (String)

    the mime-type of the content

  • :prefix (String)

    the prefix for the auto-generated DSID (not to be confused with the solr prefix)

  • :versionable (Boolean)

    is the datastream versionable



19
20
21
22
23
24
# File 'lib/active_fedora/datastream.rb', line 19

def initialize(digital_object=nil, dsid=nil, options={})
  prefix = options.delete(:prefix)
  dsid = nil if dsid == ''
  dsid ||= generate_dsid(digital_object, prefix || "DS")
  super(digital_object, dsid, options)
end

Instance Attribute Details

#digital_object=(value) ⇒ Object (writeonly)

Sets the attribute digital_object

Parameters:

  • value

    the value to set the attribute digital_object to.



6
7
8
# File 'lib/active_fedora/datastream.rb', line 6

def digital_object=(value)
  @digital_object = value
end

#last_modifiedObject

Returns the value of attribute last_modified.



7
8
9
# File 'lib/active_fedora/datastream.rb', line 7

def last_modified
  @last_modified
end

Instance Method Details

#createObject



55
56
57
58
# File 'lib/active_fedora/datastream.rb', line 55

def create
  super
  self
end

#freezeObject

Freeze datastreams such that they can be loaded from Fedora, but can’t be changed



61
62
63
# File 'lib/active_fedora/datastream.rb', line 61

def freeze
  @frozen = true
end

#frozen?Boolean

Returns:

  • (Boolean)


65
66
67
# File 'lib/active_fedora/datastream.rb', line 65

def frozen?
  !!@frozen
end

#inspectObject



33
34
35
# File 'lib/active_fedora/datastream.rb', line 33

def inspect
  "#<#{self.class} @pid=\"#{digital_object ? pid : nil}\" @dsid=\"#{dsid}\" @controlGroup=\"#{controlGroup}\" changed=\"#{changed?}\" @mimeType=\"#{mimeType}\" >"
end

#labelObject Also known as: dsLabel



28
29
30
# File 'lib/active_fedora/datastream.rb', line 28

def label
  Array(realLabel).first
end

#metadata?boolean

This method is abstract.

Override this in your concrete datastream class.

Returns does this datastream contain metadata (not file data).

Returns:

  • (boolean)

    does this datastream contain metadata (not file data)



46
47
48
# File 'lib/active_fedora/datastream.rb', line 46

def metadata?
  false
end

#profile_from_hash(profile_hash) ⇒ Object



85
86
87
88
89
# File 'lib/active_fedora/datastream.rb', line 85

def profile_from_hash(profile_hash)
  profile_hash.each_pair do |key,value|
    profile[key] = value
  end
end

#realLabelObject



26
# File 'lib/active_fedora/datastream.rb', line 26

alias_method :realLabel, :label

#saveObject



50
51
52
53
# File 'lib/active_fedora/datastream.rb', line 50

def save
  super
  self
end

#serialize!Object

serializes any changed data into the content field



70
71
# File 'lib/active_fedora/datastream.rb', line 70

def serialize!
end

#solrize_profileObject

:nodoc:



73
74
75
76
77
78
79
80
81
82
83
# File 'lib/active_fedora/datastream.rb', line 73

def solrize_profile # :nodoc:
  profile_hash = {}
  profile.each_pair do |property,value|
    if property =~ /Date/
      value = Time.parse(value) unless value.is_a?(Time)
      value = value.xmlschema
    end
    profile_hash[property] = value
  end
  profile_hash
end

#to_paramObject

compatibility method for rails’ url generators. This method will urlescape escape dots, which are apparently invalid characters in a dsid.



40
41
42
# File 'lib/active_fedora/datastream.rb', line 40

def to_param
  dsid.gsub(/\./, '%2e')
end

#to_solr(solr_doc = Hash.new) ⇒ Object



91
92
93
# File 'lib/active_fedora/datastream.rb', line 91

def to_solr(solr_doc = Hash.new)
  solr_doc
end