Class: Andrew::Person
- Inherits:
-
Object
- Object
- Andrew::Person
- Defined in:
- lib/andrewid/person.rb
Defined Under Namespace
Classes: RecordNotFound
Instance Method Summary collapse
- #department ⇒ Object
- #dump ⇒ Object
- #email ⇒ Object
- #fetch(user) ⇒ Object
- #first_name ⇒ Object
- #grade ⇒ Object
-
#initialize(andrewid) ⇒ Person
constructor
A new instance of Person.
- #last_name ⇒ Object
- #name ⇒ Object
- #school ⇒ Object
- #title ⇒ Object
- #type ⇒ Object
Constructor Details
#initialize(andrewid) ⇒ Person
Returns a new instance of Person.
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
#department ⇒ Object
69 70 71 |
# File 'lib/andrewid/person.rb', line 69 def department @data[:cmudepartment][-1] end |
#dump ⇒ Object
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 |
#email ⇒ Object
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_name ⇒ Object
33 34 35 |
# File 'lib/andrewid/person.rb', line 33 def first_name @data[:givenname][-1] end |
#grade ⇒ Object
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_name ⇒ Object
29 30 31 |
# File 'lib/andrewid/person.rb', line 29 def last_name @data[:sn][-1] end |
#name ⇒ Object
25 26 27 |
# File 'lib/andrewid/person.rb', line 25 def name @data[:cn][-1] end |
#school ⇒ Object
73 74 75 |
# File 'lib/andrewid/person.rb', line 73 def school @data[:edupersonschoolcollegename][-1] end |
#title ⇒ Object
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 |
#type ⇒ Object
45 46 47 |
# File 'lib/andrewid/person.rb', line 45 def type @data[:edupersonaffiliation][-1] end |