Sha256: e9f0af169efb02b0b3f5a5eeebe36f6d9a632ea8f482c882feb3b94b84bbb67c

Contents?: true

Size: 752 Bytes

Versions: 25

Compression:

Stored size: 752 Bytes

Contents

module Pupa
  # A list of contact details.
  class ContactDetailList < Array
    # Returns the first postal address within the list of contact details.
    #
    # @return [String,nil] a postal address
    def address
      find_by_type('address')
    end

    # Returns the first email address within the list of contact details.
    #
    # @return [String,nil] an email address
    def email
      find_by_type('email')
    end

    # Returns the value of the first contact detail matching the type.
    #
    # @param [String] a type
    # @return [String,nil] a value
    def find_by_type(type)
      find{|contact_detail|
        contact_detail[:type] == type
      }.try{|contact_detail|
        contact_detail[:value]
      }
    end
  end
end

Version data entries

25 entries across 25 versions & 1 rubygems

Version Path
pupa-0.0.10 lib/pupa/models/contact_detail_list.rb
pupa-0.0.9 lib/pupa/models/contact_detail_list.rb
pupa-0.0.8 lib/pupa/models/contact_detail_list.rb
pupa-0.0.7 lib/pupa/models/contact_detail_list.rb
pupa-0.0.6 lib/pupa/models/contact_detail_list.rb