Sha256: 161720be93b93515008f515deb58d958db3cef1f6bce811df5318dce36c1f429

Contents?: true

Size: 1.13 KB

Versions: 25

Compression:

Stored size: 1.13 KB

Contents

require "forwardable"

module Ddr::Models
  class DescriptiveMetadata
    extend Forwardable
    include Metadata

    class_attribute :mappings

    class << self
      def mapping
        @mapping ||= mappings.reduce(&:merge)
      end

      def unqualified_names
        mapping.unqualified_names
      end

      def field_names
        mapping.keys
      end
      alias_method :field_readers, :field_names

      def field_writers
        field_names.map { |name| "#{name}=".to_sym }
      end

      def property_terms
        mapping.terms.each_with_object({}) do |term, memo|
          memo[term.unqualified_name] = term.qualified_name
        end
      end

    end

    self.mappings = [ MetadataMapping.dcterms, MetadataMapping.duketerms ].freeze

    attr_reader :object

    def_delegators :object, *field_readers
    def_delegators :object, *field_writers

    mapping.each do |qualified_name, term|
      def_delegator :object, qualified_name, term.unqualified_name
      def_delegator :object, "#{qualified_name}=".to_sym, "#{term.unqualified_name}=".to_sym
    end

    def initialize(object)
      @object = object
    end

  end
end

Version data entries

25 entries across 25 versions & 1 rubygems

Version Path
ddr-models-3.0.8 lib/ddr/models/metadata/descriptive_metadata.rb
ddr-models-3.0.7 lib/ddr/models/metadata/descriptive_metadata.rb
ddr-models-3.0.6 lib/ddr/models/metadata/descriptive_metadata.rb
ddr-models-3.0.5 lib/ddr/models/metadata/descriptive_metadata.rb
ddr-models-3.0.4 lib/ddr/models/metadata/descriptive_metadata.rb
ddr-models-3.0.3 lib/ddr/models/metadata/descriptive_metadata.rb
ddr-models-3.0.2 lib/ddr/models/metadata/descriptive_metadata.rb
ddr-models-3.0.1 lib/ddr/models/metadata/descriptive_metadata.rb
ddr-models-3.0.0 lib/ddr/models/metadata/descriptive_metadata.rb
ddr-models-3.0.0.rc6 lib/ddr/models/metadata/descriptive_metadata.rb
ddr-models-3.0.0.rc5 lib/ddr/models/metadata/descriptive_metadata.rb
ddr-models-3.0.0.rc4 lib/ddr/models/metadata/descriptive_metadata.rb
ddr-models-3.0.0.rc3 lib/ddr/models/metadata/descriptive_metadata.rb
ddr-models-3.0.0.rc2 lib/ddr/models/metadata/descriptive_metadata.rb
ddr-models-3.0.0.rc1 lib/ddr/models/metadata/descriptive_metadata.rb
ddr-models-3.0.0.beta.22 lib/ddr/models/metadata/descriptive_metadata.rb
ddr-models-3.0.0.beta.21 lib/ddr/models/metadata/descriptive_metadata.rb
ddr-models-3.0.0.beta.20 lib/ddr/models/metadata/descriptive_metadata.rb
ddr-models-3.0.0.beta.18 lib/ddr/models/metadata/descriptive_metadata.rb
ddr-models-3.0.0.beta.17 lib/ddr/models/metadata/descriptive_metadata.rb