Sha256: b903e047f2acf75c9250f5b8c8762d494394e2d56b34b64755f83086d1d010fa

Contents?: true

Size: 1010 Bytes

Versions: 2

Compression:

Stored size: 1010 Bytes

Contents

require "forwardable"

module Ddr::Models
  class DescriptiveMetadata
    extend Forwardable
    include Metadata

    class << self
      def mappers
        [ MetadataMapper.dcterms, MetadataMapper.duketerms ]
      end

      def mapper
        @mapper ||= mappers.reduce(&:merge)
      end

      def mapping
        mapper.mapping
      end

      def unqualified_names
        mapper.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
    end

    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

2 entries across 2 versions & 1 rubygems

Version Path
ddr-models-3.0.0.alpha.2 lib/ddr/models/metadata/descriptive_metadata.rb
ddr-models-3.0.0.alpha.1 lib/ddr/models/metadata/descriptive_metadata.rb