Class: Cloudsponge::Contact
- Inherits:
-
Object
- Object
- Cloudsponge::Contact
- Defined in:
- lib/cloudsponge/contact.rb
Instance Attribute Summary collapse
-
#addresses ⇒ Object
Returns the value of attribute addresses.
-
#emails ⇒ Object
Returns the value of attribute emails.
-
#first_name ⇒ Object
Returns the value of attribute first_name.
-
#last_name ⇒ Object
Returns the value of attribute last_name.
-
#phones ⇒ Object
Returns the value of attribute phones.
Class Method Summary collapse
Instance Method Summary collapse
- #add_array_value(collection, value, type = nil) ⇒ Object
- #address ⇒ Object
- #email ⇒ Object
-
#initialize(contact_data) ⇒ Contact
constructor
A new instance of Contact.
- #name ⇒ Object
- #phone ⇒ Object
Constructor Details
#initialize(contact_data) ⇒ Contact
Returns a new instance of Contact.
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/cloudsponge/contact.rb', line 10 def initialize(contact_data) super() # get the basic data self.first_name = contact_data['first_name'] self.last_name = contact_data['last_name'] # get the phone numbers self.phones = [] contact_data['phone'] && contact_data['phone'].each do |phone| self.add_array_value(self.phones, phone['number'], phone['type']) end self.emails = [] contact_data['email'] && contact_data['email'].each do |email| self.add_array_value(self.emails, email['address'], email['type']) end @addresses = contact_data['address'] && contact_data['address'].inject([]) do |memo, address| memo << { :type => address['type'], :street => address["street"], :city => address["city"], :region => address["region"], :country => address["country"], :postal_code => address["postal_code"], :formatted => address["formatted"]} end || [] self end |
Instance Attribute Details
#addresses ⇒ Object
Returns the value of attribute addresses.
4 5 6 |
# File 'lib/cloudsponge/contact.rb', line 4 def addresses @addresses end |
#emails ⇒ Object
Returns the value of attribute emails.
4 5 6 |
# File 'lib/cloudsponge/contact.rb', line 4 def emails @emails end |
#first_name ⇒ Object
Returns the value of attribute first_name.
4 5 6 |
# File 'lib/cloudsponge/contact.rb', line 4 def first_name @first_name end |
#last_name ⇒ Object
Returns the value of attribute last_name.
4 5 6 |
# File 'lib/cloudsponge/contact.rb', line 4 def last_name @last_name end |
#phones ⇒ Object
Returns the value of attribute phones.
4 5 6 |
# File 'lib/cloudsponge/contact.rb', line 4 def phones @phones end |
Class Method Details
Instance Method Details
#add_array_value(collection, value, type = nil) ⇒ Object
57 58 59 |
# File 'lib/cloudsponge/contact.rb', line 57 def add_array_value(collection, value, type = nil) collection << {:value => value, :type => type} end |
#address ⇒ Object
53 54 55 |
# File 'lib/cloudsponge/contact.rb', line 53 def address self.addresses && self.addresses.first && "#{self.addresses.first[:street]} #{self.addresses.first[:city]} #{self.addresses.first[:region]}".strip end |
#email ⇒ Object
45 46 47 |
# File 'lib/cloudsponge/contact.rb', line 45 def email Contact.get_first_value(self.emails) end |
#name ⇒ Object
41 42 43 |
# File 'lib/cloudsponge/contact.rb', line 41 def name "#{self.first_name} #{self.last_name}" end |
#phone ⇒ Object
49 50 51 |
# File 'lib/cloudsponge/contact.rb', line 49 def phone Contact.get_first_value(self.phones) end |