Sha256: 0f749feb3de5680d0a2e0c7f01e98c592ff922725af048a2194f79c331abf45d

Contents?: true

Size: 1.11 KB

Versions: 14

Compression:

Stored size: 1.11 KB

Contents

module Ddr
  module Datastreams
    class MetadataDatastream < ActiveFedora::NtriplesRDFDatastream

      def self.term_names
        properties.keys.map(&:to_sym).sort
      end

      # Returns ActiveTriplesTerm now that this is an RDF datastream
      def values(term)
        term == :format ? self.format : self.send(term)
      end

      # Update term with values
      # Note that empty values (nil or "") are rejected from values array
      def set_values(term, values)
        vals = Array(values)
               .map { |v| v.to_s.strip }
               .reject { |v| v.blank? }
        begin
          self.send("#{term}=", vals)
        rescue NoMethodError
          raise ArgumentError, "No such term: #{term}"
        end
      end

      # Add value to term
      # Note that empty value (nil or "") is not added
      def add_value(term, value)
        vals = values(term).to_a << value
        set_values(term, vals)
      end

      def content_changed?
        # Patches a bug in AF RDF datastreams where
        # Content appears to change from nil to empty string
        super && !empty?
      end

    end
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
ddr-models-2.9.2 lib/ddr/datastreams/metadata_datastream.rb
ddr-models-2.9.1 lib/ddr/datastreams/metadata_datastream.rb
ddr-models-2.9.0 lib/ddr/datastreams/metadata_datastream.rb
ddr-models-2.9.0.rc1 lib/ddr/datastreams/metadata_datastream.rb
ddr-models-2.8.0 lib/ddr/datastreams/metadata_datastream.rb
ddr-models-2.8.0.rc1 lib/ddr/datastreams/metadata_datastream.rb
ddr-models-2.7.6 lib/ddr/datastreams/metadata_datastream.rb
ddr-models-2.7.5 lib/ddr/datastreams/metadata_datastream.rb
ddr-models-2.7.4 lib/ddr/datastreams/metadata_datastream.rb
ddr-models-2.7.3 lib/ddr/datastreams/metadata_datastream.rb
ddr-models-2.7.2 lib/ddr/datastreams/metadata_datastream.rb
ddr-models-2.7.1 lib/ddr/datastreams/metadata_datastream.rb
ddr-models-2.7.0 lib/ddr/datastreams/metadata_datastream.rb
ddr-models-2.7.0.rc1 lib/ddr/datastreams/metadata_datastream.rb