Module: Pupa::Concerns::Contactable

Extended by:
ActiveSupport::Concern
Included in:
Membership, Organization, Person, Post
Defined in:
lib/pupa/models/concerns/contactable.rb

Overview

Adds the Popolo contact_details property to a model.

Instance Method Summary collapse

Instance Method Details

#add_contact_detail(type, value, note: nil, label: nil, valid_from: nil, valid_until: nil) ⇒ Object

Adds a contact detail.

Parameters:

  • type (String)

    a type of medium, e.g. "fax" or "email"

  • value (String)

    a value, e.g. a phone number or email address

  • note (String) (defaults to: nil)

    a note, e.g. for grouping contact details by physical location

  • label (String) (defaults to: nil)

    a human-readable label for the contact detail

  • valid_from (String, Date, Time) (defaults to: nil)

    the date from which the contact detail is valid

  • valid_until (String, Date, Time) (defaults to: nil)

    the date from which the contact detail is no longer valid



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/pupa/models/concerns/contactable.rb', line 32

def add_contact_detail(type, value, note: nil, label: nil, valid_from: nil, valid_until: nil)
  data = {type: type, value: value}
  if note
    data[:note] = note
  end
  if label
    data[:label] = label
  end
  if valid_from
    data[:valid_from] = valid_from
  end
  if valid_until
    data[:valid_until] = valid_until
  end
  if type.present? && value.present?
    @contact_details << data
  end
end

#contact_details=(contact_details) ⇒ Object

Sets the contact details.

Parameters:

  • contact_details (Array)

    a list of contact details



20
21
22
# File 'lib/pupa/models/concerns/contactable.rb', line 20

def contact_details=(contact_details)
  @contact_details = ContactDetailList.new(symbolize_keys(contact_details))
end

#initialize(*args) ⇒ Object



12
13
14
15
# File 'lib/pupa/models/concerns/contactable.rb', line 12

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