Class: CMU::Person
- Inherits:
-
Object
- Object
- CMU::Person
- Defined in:
- lib/cmu_person/person.rb
Overview
A CMU::Person class
Class Method Summary collapse
-
.find(andrew_id) ⇒ CMU::Person
Attempts to create and return a new CMU::Person from the CMU LDAP directory.
-
.find_by_andrew_id(andrew_id) ⇒ CMU::Person
Attempts to create and return a new CMU::Person from the CMU LDAP directory.
Instance Method Summary collapse
-
#andrew_id ⇒ String
Returns the Andrew ID of the CMU Person.
-
#department ⇒ String?
Returns department for the CMU Person.
-
#email ⇒ String
Returns the email of the CMU Person.
-
#first_name ⇒ String
Returns the first name of the CMU Person.
-
#grade ⇒ String?
Returns the String representation of the grade of the CMU Person.
-
#initialize(andrew_id) ⇒ Person
constructor
::nodoc::.
-
#inspect ⇒ Object
::nodoc::.
-
#last_name ⇒ String
Returns the last name of the CMU Person.
-
#name ⇒ String
Returns the full name of the CMU Person.
-
#phone ⇒ String?
Returns the phone number for the CMU Person.
-
#school ⇒ String?
Returns the “college” for the CMU Person.
-
#title ⇒ String?
Returns the official title for the CMU Person.
-
#to_s ⇒ Object
::nodoc::.
-
#type ⇒ String
Returns the type for the CMU Person.
Constructor Details
#initialize(andrew_id) ⇒ Person
- ::nodoc
33 34 35 36 37 |
# File 'lib/cmu_person/person.rb', line 33 def initialize(andrew_id) ldap = Net::LDAP.new(:host => 'ldap.andrew.cmu.edu') @data = ldap.search(:base => 'ou=Person,dc=cmu,dc=edu', :filter => 'cmuAndrewId=' + andrew_id).first raise CMU::RecordNotFound if @data.nil? end |
Class Method Details
.find(andrew_id) ⇒ CMU::Person
Attempts to create and return a new CMU::Person from the CMU LDAP directory.
13 14 15 |
# File 'lib/cmu_person/person.rb', line 13 def self.find(andrew_id) CMU::Person.new(andrew_id) end |
.find_by_andrew_id(andrew_id) ⇒ CMU::Person
Attempts to create and return a new CMU::Person from the CMU LDAP directory.
Unlink (see #find), this method will not raise an exception if the Andrew
ID is not found.
23 24 25 26 27 28 29 |
# File 'lib/cmu_person/person.rb', line 23 def self.find_by_andrew_id(andrew_id) begin find(andrew_id) rescue nil end end |
Instance Method Details
#andrew_id ⇒ String
Returns the Andrew ID of the CMU Person
42 43 44 |
# File 'lib/cmu_person/person.rb', line 42 def andrew_id @andrew_id ||= @data[:cmuAndrewId].last end |
#department ⇒ String?
Returns department for the CMU Person
132 133 134 |
# File 'lib/cmu_person/person.rb', line 132 def department @department ||= @data[:cmudepartment].last end |
#email ⇒ String
Returns the email of the CMU Person. If the CMU Person has
listed a preferred email, it will be displayed. Otherwise,
the official Andrew Email will be used.
72 73 74 75 76 77 78 |
# File 'lib/cmu_person/person.rb', line 72 def email if @data.attribute_names.include?(:cmupreferredmail) @email ||= @data[:cmupreferredmail].last else @email ||= @data[:mail].last end end |
#first_name ⇒ String
Returns the first name of the CMU Person
63 64 65 |
# File 'lib/cmu_person/person.rb', line 63 def first_name @first_name ||= @data[:givenname].last end |
#grade ⇒ String?
Returns the String representation of the grade of the CMU Person
120 121 122 123 124 125 126 |
# File 'lib/cmu_person/person.rb', line 120 def grade if @data.attribute_names.include?(:cmustudentclass) @grade ||= @data[:cmustudentclass].last else @grade ||= nil end end |
#inspect ⇒ Object
- ::nodoc
146 147 148 149 |
# File 'lib/cmu_person/person.rb', line 146 def inspect fields = %w(andrew_id first_name last_name email phone type title) @inspect ||= "<CMU::Person #{fields.collect{|f| f + ': ' + self.send(f.to_sym).inspect}.join(', ')}>" end |
#last_name ⇒ String
Returns the last name of the CMU Person
56 57 58 |
# File 'lib/cmu_person/person.rb', line 56 def last_name @last_name ||= @data[:sn].last end |
#name ⇒ String
Returns the full name of the CMU Person
49 50 51 |
# File 'lib/cmu_person/person.rb', line 49 def name @name ||= @data[:cn].last end |
#phone ⇒ String?
Returns the phone number for the CMU Person
84 85 86 87 88 89 90 |
# File 'lib/cmu_person/person.rb', line 84 def phone if @data.attribute_names.include?(:cmupreferredtelephone) @phone ||= @data[:cmupreferredtelephone].last.gsub(/[^0-9]/,'') else @phone ||= nil end end |
#school ⇒ String?
Returns the “college” for the CMU Person
139 140 141 142 |
# File 'lib/cmu_person/person.rb', line 139 def school filters = ['Student Employment', 'Undergraduate Admission and Student Aid', 'VP For Campus Affairs'] @school ||= @data[:edupersonschoolcollegename].reject{|c| filters.include?(c)}.last end |
#title ⇒ String?
Returns the official title for the CMU Person
103 104 105 106 107 108 109 110 111 112 113 |
# File 'lib/cmu_person/person.rb', line 103 def title if @data.attribute_names.include?(:title) @title ||= @data[:title].last else if @data.attribute_names.include?(:cmutitle) @title ||= @data[:cmutitle].last else @title ||= nil end end end |
#to_s ⇒ Object
- ::nodoc
153 154 155 |
# File 'lib/cmu_person/person.rb', line 153 def to_s @to_s ||= "<CMU::Person \"#{self.send(:name)} (#{self.send(:andrew_id)})\">" end |
#type ⇒ String
Returns the type for the CMU Person
95 96 97 |
# File 'lib/cmu_person/person.rb', line 95 def type @type ||= @data[:edupersonaffiliation].last end |