Sha256: d56681087599469692f23a8ac3e456f2153a6113e299ee5da6bf6acf15a33db2

Contents?: true

Size: 860 Bytes

Versions: 14

Compression:

Stored size: 860 Bytes

Contents

module Ddr::Models
  module Metadata

    def values(term)
      self.send(term)
    end

    # Update term with values
    # Note that empty values (nil or "") are rejected from values array
    def set_values(term, values)
      if values.respond_to?(:reject!)
        values.reject! { |v| v.blank? }
      else
        values = nil if values.blank?
      end
      begin
        self.send("#{term}=", values)
      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)
      begin
        unless value.blank?
          values = values(term).to_a << value
          set_values term, values
        end
      rescue NoMethodError
        raise ArgumentError, "No such term: #{term}"
      end
    end

  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
ddr-models-3.0.0.beta.11 lib/ddr/models/metadata/metadata.rb
ddr-models-3.0.0.beta.10 lib/ddr/models/metadata/metadata.rb
ddr-models-3.0.0.beta.9 lib/ddr/models/metadata/metadata.rb
ddr-models-3.0.0.beta.8 lib/ddr/models/metadata/metadata.rb
ddr-models-3.0.0.beta.7 lib/ddr/models/metadata/metadata.rb
ddr-models-3.0.0.beta.6 lib/ddr/models/metadata/metadata.rb
ddr-models-3.0.0.beta.4 lib/ddr/models/metadata/metadata.rb
ddr-models-3.0.0.beta.3 lib/ddr/models/metadata/metadata.rb
ddr-models-3.0.0.beta.2 lib/ddr/models/metadata/metadata.rb
ddr-models-3.0.0.beta.1 lib/ddr/models/metadata/metadata.rb
ddr-models-3.0.0.alpha.4 lib/ddr/models/metadata/metadata.rb
ddr-models-3.0.0.alpha.3 lib/ddr/models/metadata/metadata.rb
ddr-models-3.0.0.alpha.2 lib/ddr/models/metadata/metadata.rb
ddr-models-3.0.0.alpha.1 lib/ddr/models/metadata/metadata.rb