Class: Contact

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(fname, lname, email, phone, mobile, im, pager, title = nil, organization = nil, location = nil, note = nil) ⇒ Contact

Returns a new instance of Contact.



137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
# File 'lib/contact.rb', line 137

def initialize (fname, lname, email, phone, mobile, im, pager, title=nil, organization=nil, location=nil, note=nil)
	#fnamelname have to be uniq
	@firstname=fname
	@lastname=lname
	@email=email
	@phone=phone
	@mobile=mobile
	@im=im
	@pager=pager
	@title=title
	@organization=organization
	@location=location
	@note=note
	@nb_use=0	
end

Instance Attribute Details

#emailObject

Returns the value of attribute email.



2
3
4
# File 'lib/contact.rb', line 2

def email
  @email
end

#firstnameObject

Returns the value of attribute firstname.



2
3
4
# File 'lib/contact.rb', line 2

def firstname
  @firstname
end

#imObject

Returns the value of attribute im.



2
3
4
# File 'lib/contact.rb', line 2

def im
  @im
end

#lastnameObject

Returns the value of attribute lastname.



2
3
4
# File 'lib/contact.rb', line 2

def lastname
  @lastname
end

#locationObject

Returns the value of attribute location.



2
3
4
# File 'lib/contact.rb', line 2

def location
  @location
end

#mobileObject

Returns the value of attribute mobile.



2
3
4
# File 'lib/contact.rb', line 2

def mobile
  @mobile
end

#nb_useObject

Returns the value of attribute nb_use.



2
3
4
# File 'lib/contact.rb', line 2

def nb_use
  @nb_use
end

#noteObject

Returns the value of attribute note.



2
3
4
# File 'lib/contact.rb', line 2

def note
  @note
end

#organizationObject

Returns the value of attribute organization.



2
3
4
# File 'lib/contact.rb', line 2

def organization
  @organization
end

#pagerObject

Returns the value of attribute pager.



2
3
4
# File 'lib/contact.rb', line 2

def pager
  @pager
end

#phoneObject

Returns the value of attribute phone.



2
3
4
# File 'lib/contact.rb', line 2

def phone
  @phone
end

#titleObject

Returns the value of attribute title.



2
3
4
# File 'lib/contact.rb', line 2

def title
  @title
end

Class Method Details

.add_contact(firstname, lastname, email, phone, mobile, im, pager, title, organization, location, note) ⇒ Object

add a contact



7
8
9
10
11
12
13
# File 'lib/contact.rb', line 7

def Contact::add_contact(firstname, lastname, email, phone, mobile, im, pager, title, organization, location, note)
	if $contact["#{firstname}|#{lastname}"] == nil
		$contact["#{firstname}|#{lastname}"] = Contact.new(firstname, lastname, email, phone, mobile, im, pager, title, organization, location, note)
		return true
	end
	return false
end

.add_use(firstname, lastname) ⇒ Object



153
154
155
156
# File 'lib/contact.rb', line 153

def Contact::add_use(firstname, lastname)
	$contact["#{firstname}|#{lastname}"].nb_use+=1
	Contact::used?(firstname, lastname)
end

.contact_exist?(firstname, lastname) ⇒ Boolean

check if a contact is defined

Returns:

  • (Boolean)


124
125
126
# File 'lib/contact.rb', line 124

def Contact::contact_exist?(firstname, lastname)
	return $contact["#{firstname}|#{lastname}"] != nil
end

.contact_nb_entryObject

return number of contact



131
132
133
# File 'lib/contact.rb', line 131

def Contact::contact_nb_entry()
	return $contact.size
end

.del_contact(firstname, lastname) ⇒ Object

delete a contact return true is entry delete otherwise false



20
21
22
23
24
25
26
# File 'lib/contact.rb', line 20

def Contact::del_contact(firstname, lastname)
	if !Contact::used?(firstname,lastname)
		$contact.delete("#{firstname}|#{lastname}")
		return true
	end
	return false
end

.del_use(firstname, lastname) ⇒ Object



158
159
160
161
# File 'lib/contact.rb', line 158

def Contact::del_use(firstname, lastname)
	$contact["#{firstname}|#{lastname}"].nb_use-=1
	Contact::used?(firstname, lastname)
end

.get_contact_email(firstname, lastname) ⇒ Object

return contact’s email



49
50
51
52
53
# File 'lib/contact.rb', line 49

def Contact::get_contact_email(firstname, lastname)
	if Contact::contact_exist?(firstname, lastname)
		return $contact["#{firstname}|#{lastname}"].email
	end
end

.get_contact_im(firstname, lastname) ⇒ Object

return contact’s im



67
68
69
70
71
# File 'lib/contact.rb', line 67

def Contact::get_contact_im(firstname, lastname)
	if Contact::contact_exist?(firstname, lastname)
		return $contact["#{firstname}|#{lastname}"].im
	end
end

.get_contact_mobile(firstname, lastname) ⇒ Object

return contact’s mobile



58
59
60
61
62
# File 'lib/contact.rb', line 58

def Contact::get_contact_mobile(firstname, lastname)
	if Contact::contact_exist?(firstname, lastname)
		return $contact["#{firstname}|#{lastname}"].mobile
	end
end

.get_contact_organization(firstname, lastname) ⇒ Object

return contact’s organization



40
41
42
43
44
# File 'lib/contact.rb', line 40

def Contact::get_contact_organization(firstname, lastname)
	if Contact::contact_exist?(firstname, lastname)
		return $contact["#{firstname}|#{lastname}"].organization
	end
end

.get_contact_title(firstname, lastname) ⇒ Object

return contact’s title



31
32
33
34
35
# File 'lib/contact.rb', line 31

def Contact::get_contact_title(firstname, lastname)
	if Contact::contact_exist?(firstname, lastname)
		return $contact["#{firstname}|#{lastname}"].title
	end
end

.set_email(firstname, lastname, email) ⇒ Object



93
94
95
# File 'lib/contact.rb', line 93

def Contact::set_email(firstname, lastname, email)
	$contact["#{firstname}|#{lastname}"].email=email
end

.set_im(firstname, lastname, im) ⇒ Object



109
110
111
# File 'lib/contact.rb', line 109

def Contact::set_im(firstname, lastname, im)
	$contact["#{firstname}|#{lastname}"].im=im
end

.set_location(firstname, lastname, location) ⇒ Object



113
114
115
# File 'lib/contact.rb', line 113

def Contact::set_location(firstname, lastname, location)
	$contact["#{firstname}|#{lastname}"].location=location
end

.set_mobile(firstname, lastname, mobile) ⇒ Object



101
102
103
# File 'lib/contact.rb', line 101

def Contact::set_mobile(firstname, lastname, mobile)
	$contact["#{firstname}|#{lastname}"].mobile=mobile
end

.set_note(firstname, lastname, note) ⇒ Object



117
118
119
# File 'lib/contact.rb', line 117

def Contact::set_note(firstname, lastname, note)
	$contact["#{firstname}|#{lastname}"].note=note
end

.set_organization(firstname, lastname, organization) ⇒ Object



88
89
90
# File 'lib/contact.rb', line 88

def Contact::set_organization(firstname, lastname, organization)
	$contact["#{firstname}|#{lastname}"].organization=organization
end

.set_pager(firstname, lastname, pager) ⇒ Object



105
106
107
# File 'lib/contact.rb', line 105

def Contact::set_pager(firstname, lastname, pager)
	$contact["#{firstname}|#{lastname}"].pager=pager
end

.set_phone(firstname, lastname, phone) ⇒ Object



97
98
99
# File 'lib/contact.rb', line 97

def Contact::set_phone(firstname, lastname, phone)
	$contact["#{firstname}|#{lastname}"].phone=phone
end

.set_title(firstname, lastname, title) ⇒ Object



84
85
86
# File 'lib/contact.rb', line 84

def Contact::set_title(firstname, lastname, title)
	$contact["#{firstname}|#{lastname}"].title=title
end

.used?(firstname, lastname) ⇒ Boolean

Returns:

  • (Boolean)


163
164
165
# File 'lib/contact.rb', line 163

def Contact::used?(firstname, lastname)
	return $contact["#{firstname}|#{lastname}"].nb_use>0 
end

Instance Method Details

#get_contact_nameObject

return a table of all contact



76
77
78
79
80
81
82
# File 'lib/contact.rb', line 76

def get_contact_name()
	name_t=[]
	$contact.each_key {|name|
		name_t.push name
	}
	return name_t
end

#to_strObject



167
168
169
# File 'lib/contact.rb', line 167

def to_str()
	print "Contact: ", @firstname, " ", @lastname, " ", @email, " ", @phone, " ", @mobile, " ", @im, " ", @pager, " ", @title, " ", @organization, " ", @location, " ", @note,"\n"
end