Class: ContactCsv::Contact

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

Overview

Contact

Object that represents a Contact from an address book. This class is meant to support the most common attributes.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes = {}) ⇒ Contact

Initializes a Contact objest and will take a hash of the attributes with values

Contact.new(:first_name => “Willy”, :last_name => “Wonka”)



12
13
14
15
16
17
18
19
# File 'lib/contact_csv/contact.rb', line 12

def initialize(attributes={})
  @extras = {}
  @first_name = attributes[:first_name]
  @middle_name = attributes[:middle_name]
  @last_name = attributes[:last_name]
  @email = attributes[:email]
  @title = attributes[:title]
end

Instance Attribute Details

#emailObject

Returns the value of attribute email.



7
8
9
# File 'lib/contact_csv/contact.rb', line 7

def email
  @email
end

#extrasObject

Returns a hash of all attributes that could not be mapped to a Contact class attribute



22
23
24
# File 'lib/contact_csv/contact.rb', line 22

def extras
  @extras
end

#first_nameObject

Returns the value of attribute first_name.



7
8
9
# File 'lib/contact_csv/contact.rb', line 7

def first_name
  @first_name
end

#last_nameObject

Returns the value of attribute last_name.



7
8
9
# File 'lib/contact_csv/contact.rb', line 7

def last_name
  @last_name
end

#middle_nameObject

Returns the value of attribute middle_name.



7
8
9
# File 'lib/contact_csv/contact.rb', line 7

def middle_name
  @middle_name
end

#titleObject

Returns the value of attribute title.



7
8
9
# File 'lib/contact_csv/contact.rb', line 7

def title
  @title
end

Instance Method Details

#add_extra(extra) ⇒ Object

Adds an unmappable attribute



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

def add_extra(extra)
  @extras.merge!(extra)
end

#full_nameObject

First name and last name



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

def full_name
  [@first_name, @last_name].join(' ')
end