Class: ActiveFedora::Datastream
- Inherits:
-
Rubydora::Datastream
- Object
- Rubydora::Datastream
- ActiveFedora::Datastream
- Defined in:
- lib/active_fedora/datastream.rb
Overview
This class represents a Fedora datastream
Direct Known Subclasses
Instance Attribute Summary (collapse)
-
- (Object) digital_object
writeonly
Sets the attribute digital_object.
-
- (Object) dirty
Returns the value of attribute dirty.
-
- (Object) fields
Returns the value of attribute fields.
-
- (Object) last_modified
Returns the value of attribute last_modified.
Class Method Summary (collapse)
-
+ (Object) from_xml(tmpl, node)
Populate a Datastream object based on the "datastream" node from a FOXML file.
Instance Method Summary (collapse)
- - (Object) add_ds_location
- - (Object) add_mime_type
- - (Object) create
-
- (Boolean) dirty?
Test whether this datastream been modified since it was last saved.
-
- (Datastream) initialize(digital_object, dsid, options = {})
constructor
A new instance of Datastream.
- - (Object) inspect
- - (Boolean) new_object?
- - (Object) profile_from_hash(profile_hash)
- - (Object) save
-
- (Object) serialize!
serializes any changed data into the content field.
- - (Object) size
-
- (Object) solrize_profile
:nodoc:.
-
- (Object) to_param
compatibility method for rails' url generators.
- - (Object) validate_content_present
Constructor Details
- (Datastream) initialize(digital_object, dsid, options = {})
A new instance of Datastream
10 11 12 13 14 15 |
# File 'lib/active_fedora/datastream.rb', line 10 def initialize(digital_object, dsid, ={}) ## When you use the versions feature of rubydora (0.5.x), you need to have a 3 argument constructor self.fields={} self.dirty = false super end |
Instance Attribute Details
- (Object) digital_object=(value) (writeonly)
Sets the attribute digital_object
6 7 8 |
# File 'lib/active_fedora/datastream.rb', line 6 def digital_object=(value) @digital_object = value end |
- (Object) dirty
Returns the value of attribute dirty
7 8 9 |
# File 'lib/active_fedora/datastream.rb', line 7 def dirty @dirty end |
- (Object) fields
Returns the value of attribute fields
7 8 9 |
# File 'lib/active_fedora/datastream.rb', line 7 def fields @fields end |
- (Object) last_modified
Returns the value of attribute last_modified
7 8 9 |
# File 'lib/active_fedora/datastream.rb', line 7 def last_modified @last_modified end |
Class Method Details
+ (Object) from_xml(tmpl, node)
Populate a Datastream object based on the "datastream" node from a FOXML file
86 87 88 89 90 |
# File 'lib/active_fedora/datastream.rb', line 86 def self.from_xml(tmpl, node) tmpl.instance_variable_set(:@dirty, false) tmpl.controlGroup= node['CONTROL_GROUP'] tmpl end |
Instance Method Details
- (Object) add_ds_location
25 26 27 28 |
# File 'lib/active_fedora/datastream.rb', line 25 def add_ds_location if self.controlGroup == 'E' end end |
- (Object) add_mime_type
21 22 23 |
# File 'lib/active_fedora/datastream.rb', line 21 def add_mime_type self.mimeType = 'text/xml' unless self.mimeType end |
- (Object) create
71 72 73 74 75 76 77 |
# File 'lib/active_fedora/datastream.rb', line 71 def create run_callbacks :create do repository.add_datastream to_api_params.merge({ :pid => pid, :dsid => dsid }) reset_profile_attributes self end end |
- (Boolean) dirty?
Test whether this datastream been modified since it was last saved
42 43 44 |
# File 'lib/active_fedora/datastream.rb', line 42 def dirty? dirty || changed? end |
- (Object) inspect
30 31 32 |
# File 'lib/active_fedora/datastream.rb', line 30 def inspect "#<#{self.class}:#{self.hash} @pid=\"#{digital_object ? pid : nil}\" @dsid=\"#{dsid}\" @controlGroup=\"#{controlGroup}\" @dirty=\"#{dirty}\" @mimeType=\"#{mimeType}\" >" end |
- (Boolean) new_object?
46 47 48 |
# File 'lib/active_fedora/datastream.rb', line 46 def new_object? new? end |
- (Object) profile_from_hash(profile_hash)
104 105 106 107 108 |
# File 'lib/active_fedora/datastream.rb', line 104 def profile_from_hash(profile_hash) profile_hash.each_pair do |key,value| profile[key] = value.to_s end end |
- (Object) save
61 62 63 64 65 66 67 68 69 |
# File 'lib/active_fedora/datastream.rb', line 61 def save run_callbacks :save do return create if new? repository.modify_datastream to_api_params.merge({ :pid => pid, :dsid => dsid }) reset_profile_attributes #Datastream.new(digital_object, dsid) self end end |
- (Object) serialize!
serializes any changed data into the content field
81 82 |
# File 'lib/active_fedora/datastream.rb', line 81 def serialize! end |
- (Object) size
17 18 19 |
# File 'lib/active_fedora/datastream.rb', line 17 def size self.profile['dsSize'] end |
- (Object) solrize_profile
:nodoc:
92 93 94 95 96 97 98 99 100 101 102 |
# File 'lib/active_fedora/datastream.rb', line 92 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 |
- (Object) to_param
compatibility method for rails' url generators. This method will urlescape escape dots, which are apparently invalid characters in a dsid.
37 38 39 |
# File 'lib/active_fedora/datastream.rb', line 37 def to_param dsid.gsub(/\./, '%2e') end |
- (Object) validate_content_present
50 51 52 53 54 55 56 57 58 59 |
# File 'lib/active_fedora/datastream.rb', line 50 def validate_content_present case controlGroup when 'X','M' @content.present? when 'E','R' dsLocation.present? else raise "Invalid control group: #{controlGroup.inspect}" end end |