Class: Rails::Contact::Contact
- Inherits:
-
ApplicationRecord
- Object
- ActiveRecord::Base
- ApplicationRecord
- Rails::Contact::Contact
- Defined in:
- app/models/rails/contact/contact.rb
Instance Attribute Summary collapse
-
#labels_csv ⇒ Object
Returns the value of attribute labels_csv.
Instance Method Summary collapse
- #full_name ⇒ Object
- #meta(key) ⇒ Object
- #metadata_hash ⇒ Object
- #primary_email ⇒ Object
- #primary_phone ⇒ Object
- #set_labels_from_csv!(csv_string) ⇒ Object
Instance Attribute Details
#labels_csv ⇒ Object
Returns the value of attribute labels_csv.
7 8 9 |
# File 'app/models/rails/contact/contact.rb', line 7 def labels_csv @labels_csv end |
Instance Method Details
#full_name ⇒ Object
26 27 28 |
# File 'app/models/rails/contact/contact.rb', line 26 def full_name [ given_name, family_name ].compact.join(" ").strip end |
#meta(key) ⇒ Object
38 39 40 |
# File 'app/models/rails/contact/contact.rb', line 38 def (key) [key.to_s] end |
#metadata_hash ⇒ Object
51 52 53 54 55 56 57 58 59 60 |
# File 'app/models/rails/contact/contact.rb', line 51 def value = return value if value.is_a?(Hash) return {} if value.blank? parsed = JSON.parse(value) parsed.is_a?(Hash) ? parsed : {} rescue JSON::ParserError {} end |
#primary_email ⇒ Object
30 31 32 |
# File 'app/models/rails/contact/contact.rb', line 30 def primary_email emails.find(&:primary?) || emails.first end |
#primary_phone ⇒ Object
34 35 36 |
# File 'app/models/rails/contact/contact.rb', line 34 def primary_phone phones.find(&:primary?) || phones.first end |
#set_labels_from_csv!(csv_string) ⇒ Object
42 43 44 45 |
# File 'app/models/rails/contact/contact.rb', line 42 def set_labels_from_csv!(csv_string) names = csv_string.to_s.split(",").map(&:strip).reject(&:empty?).uniq self.labels = names.map { |name| Rails::Contact::Label.find_or_create_by!(name: name) } end |