Sha256: 2320cff4f34db13024a0e5e314130fcb2c2ff9bc0ce10c3a395356ea035e74c0

Contents?: true

Size: 1.08 KB

Versions: 1

Compression:

Stored size: 1.08 KB

Contents

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

      included do
        attr_reader :contact_details
        dump :contact_details
      end

      def initialize(*args)
        @contact_details = ContactDetailList.new
        super
      end

      # Sets the contact details.
      #
      # @param [Array] contact_details a list of contact details
      def contact_details=(contact_details)
        @contact_details = ContactDetailList.new(contact_details)
      end

      # Adds a contact detail.
      #
      # @param [String] type a type of medium, e.g. "fax" or "email"
      # @param [String] value a value, e.g. a phone number or email address
      # @param [String] note a note, e.g. for grouping contact details by physical location
      def add_contact_detail(type, value, note: nil)
        data = {type: type, value: value}
        if note
          data[:note] = note
        end
        if type && value
          @contact_details << 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/contactable.rb