Sha256: 6fe8d81a7f432f1a6a4351ca893de46e618aa1e6f10e3ab6dec1bd8f2123ac92

Contents?: true

Size: 1013 Bytes

Versions: 1

Compression:

Stored size: 1013 Bytes

Contents

module Pupa
  module Concerns
    # Adds the Popolo `other_names` property to a model.
    module Nameable
      extend ActiveSupport::Concern

      included do
        attr_accessor :other_names
        dump :other_names
      end

      def initialize(*args)
        @other_names = []
        super
      end

      # Adds an alternate or former name.
      #
      # @param [String] name an alternate or former name
      # @param [Date,Time] start_date the date on which the name was adopted
      # @param [Date,Time] end_date the date on which the name was abandoned
      # @param [String] note a note, e.g. "Birth name"
      def add_name(name, start_date: nil, end_date: nil, note: nil)
        data = {name: name}
        if start_date
          data[:start_date] = start_date
        end
        if end_date
          data[:end_date] = end_date
        end
        if note
          data[:note] = note
        end
        if name
          @other_names << data
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
pupa-0.0.10 lib/pupa/models/concerns/nameable.rb