Class: Andrew::Person

Inherits:
Object
  • Object
show all
Defined in:
lib/andrewid/person.rb

Defined Under Namespace

Classes: RecordNotFound

Instance Method Summary collapse

Constructor Details

#initialize(andrewid) ⇒ Person

Returns a new instance of Person.

Raises:



8
9
10
# File 'lib/andrewid/person.rb', line 8

def initialize(andrewid)
  raise RecordNotFound, "Invalid AndrewID" unless @data = fetch(andrewid)
end

Instance Method Details

#departmentObject



69
70
71
# File 'lib/andrewid/person.rb', line 69

def department
 @data[:cmudepartment][-1]
end

#dumpObject



19
20
21
22
# File 'lib/andrewid/person.rb', line 19

def dump
  @data.each{|i,j| puts i.to_s.ljust(30)+":\t"+(j.is_a?(Array) ? "[ "+j.join(", ")+" ]" : j.to_s)+"\n"}
  nil
end

#emailObject



37
38
39
40
41
42
43
# File 'lib/andrewid/person.rb', line 37

def email
  if @data.attribute_names.include? :cmupreferredmail then
  @data[:cmupreferredmail][-1]
 else
    @data[:mail][-1]
  end
end

#fetch(user) ⇒ Object



12
13
14
15
16
17
# File 'lib/andrewid/person.rb', line 12

def fetch(user)
  host = "ldap.andrew.cmu.edu"
  ldap = Net::LDAP.new :host => host, :port => 389
  ldap.search( :base => 'ou=Person,dc=cmu,dc=edu', 
               :filter => 'cmuAndrewId='+user )[0] 
end

#first_nameObject



33
34
35
# File 'lib/andrewid/person.rb', line 33

def first_name
@data[:givenname][-1]
end

#gradeObject



61
62
63
64
65
66
67
# File 'lib/andrewid/person.rb', line 61

def grade
  if @data.attribute_names.include? :cmustudentclass then
    @data[:cmustudentclass][-1]
  else
    nil
  end
end

#last_nameObject



29
30
31
# File 'lib/andrewid/person.rb', line 29

def last_name
@data[:sn][-1]
end

#nameObject



25
26
27
# File 'lib/andrewid/person.rb', line 25

def name
@data[:cn][-1]
end

#schoolObject



73
74
75
# File 'lib/andrewid/person.rb', line 73

def school
 @data[:edupersonschoolcollegename][-1]
end

#titleObject



49
50
51
52
53
54
55
56
57
58
59
# File 'lib/andrewid/person.rb', line 49

def title
    if @data.attribute_names.include? :title then
    @data[:title][-1]
  else
    if @data.attribute_names.include? :cmutitle then
      @data[:cmutitle][-1]
    else
      nil
    end
  end    
end

#typeObject



45
46
47
# File 'lib/andrewid/person.rb', line 45

def type 
  @data[:edupersonaffiliation][-1]
end