Class: UCB::LDAP::Address

Inherits:
Entry
  • Object
show all
Defined in:
lib/ucb_ldap_address.rb

Overview

UCB::LDAP::Address

This class models a person address instance in the UCB LDAP directory.

a = Address.find_by_uid("1234")       #=> [#<UCB::LDAP::Address: ...>, ...]

Addresses are usually loaded through a Person instance:

p = Person.find_by_uid("1234")    #=> #<UCB::LDAP::Person: ...>
addrs = p.addresses               #=> [#<UCB::LDAP::Address: ...>, ...]

Note on Binds

You must have a privileged bind and pass your credentials to UCB::LDAP.authenticate() before performing your Address search.

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Entry

#assigned_attributes, #attributes, canonical, #canonical, combine_filters, create, create!, #delete, #delete!, #dn, entity_name, find_by_dn, #initialize, make_search_filter, #method_missing, #modify, #modify_operations, #net_ldap, net_ldap, object_classes, schema_attribute, schema_attributes_array, schema_attributes_hash, search, set_schema_attributes, #setter_method?, tree_base, tree_base=, unique_object_class, #update_attributes, #update_attributes!, #value_getter, #value_setter

Constructor Details

This class inherits a constructor from UCB::LDAP::Entry

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class UCB::LDAP::Entry

Class Method Details

.find_by_uid(uid) ⇒ Object

Returns an Array of Address for uid, sorted by sort_order(). Returns an empty Array ([]) if nothing is found.



97
98
99
100
101
# File 'lib/ucb_ldap_address.rb', line 97

def find_by_uid(uid)
  base = "uid=#{uid},ou=people,dc=berkeley,dc=edu"
  filter = Net::LDAP::Filter.eq("objectclass", 'berkeleyEduPersonAddress')
  search(:base => base, :filter => filter).sort_by{|addr| addr.sort_order}
end

Instance Method Details

#address_typeObject



27
28
29
# File 'lib/ucb_ldap_address.rb', line 27

def address_type
  berkeleyEduPersonAddressType
end

#building_codeObject



31
32
33
# File 'lib/ucb_ldap_address.rb', line 31

def building_code
  berkeleyEduPersonAddressBuildingCode
end

#cityObject



35
36
37
# File 'lib/ucb_ldap_address.rb', line 35

def city
  l.first
end

#country_codeObject



39
40
41
# File 'lib/ucb_ldap_address.rb', line 39

def country_code
  berkeleyEduPersonAddressCountryCode
end

#department_acronymObject



47
48
49
# File 'lib/ucb_ldap_address.rb', line 47

def department_acronym
  berkeleyEduPersonAddressUnitHRDeptName
end

#department_nameObject



43
44
45
# File 'lib/ucb_ldap_address.rb', line 43

def department_name
  berkeleyEduPersonAddressUnitCalNetDeptName
end

#directoriesObject



51
52
53
# File 'lib/ucb_ldap_address.rb', line 51

def directories
  berkeleyEduPersonAddressPublications
end

#emailObject

Returns email address associated with this Address.



56
57
58
# File 'lib/ucb_ldap_address.rb', line 56

def email
  mail.first
end

#mail_codeObject



60
61
62
# File 'lib/ucb_ldap_address.rb', line 60

def mail_code
  berkeleyEduPersonAddressMailCode
end

#mail_release?Boolean

Returns:

  • (Boolean)


64
65
66
# File 'lib/ucb_ldap_address.rb', line 64

def mail_release?
  berkeleyEduEmailRelFlag
end

#phoneObject



68
69
70
# File 'lib/ucb_ldap_address.rb', line 68

def phone
  telephoneNumber.first
end

#postal_addressObject

Returns postal address as an Array.

addr.attribute(:postalAddress) #=> '501 Banway Bldg.$Berkeley, CA 94720-3814$USA'
addr.postal_address            #=> ['501 Banway Bldg.', 'Berkeley, CA 94720-3814', 'USA']


77
78
79
# File 'lib/ucb_ldap_address.rb', line 77

def postal_address
  postalAddress == [] ? nil : postalAddress.split("$")  
end

#primary_work_address?Boolean

Returns:

  • (Boolean)


23
24
25
# File 'lib/ucb_ldap_address.rb', line 23

def primary_work_address?
  berkeleyEduPersonAddressPrimaryFlag
end

#sort_orderObject



81
82
83
# File 'lib/ucb_ldap_address.rb', line 81

def sort_order
  berkeleyEduPersonAddressSortOrder.first || 0
end

#stateObject



85
86
87
# File 'lib/ucb_ldap_address.rb', line 85

def state
  st.first
end

#zipObject



89
90
91
# File 'lib/ucb_ldap_address.rb', line 89

def zip
  postalCode
end