Class: FruitToLime::Person
- Inherits:
-
PersonReference
- Object
- PersonReference
- FruitToLime::Person
- Includes:
- ModelHasCustomFields, ModelHasTags, SerializeHelper
- Defined in:
- lib/fruit_to_lime/model/person.rb
Instance Attribute Summary collapse
-
#alternative_email ⇒ Object
Returns the value of attribute alternative_email.
-
#currently_employed ⇒ Object
Returns the value of attribute currently_employed.
-
#custom_values ⇒ Object
readonly
you add custom values by using ModelHasCustomFields#set_custom_value.
-
#direct_phone_number ⇒ Object
Returns the value of attribute direct_phone_number.
-
#email ⇒ Object
Returns the value of attribute email.
-
#fax_phone_number ⇒ Object
Returns the value of attribute fax_phone_number.
-
#first_name ⇒ Object
Returns the value of attribute first_name.
-
#home_phone_number ⇒ Object
Returns the value of attribute home_phone_number.
-
#last_name ⇒ Object
Returns the value of attribute last_name.
-
#mobile_phone_number ⇒ Object
Returns the value of attribute mobile_phone_number.
-
#organization ⇒ Object
you add custom values by using ModelHasCustomFields#set_custom_value.
-
#position ⇒ Object
Returns the value of attribute position.
-
#postal_address ⇒ Object
Returns the value of attribute postal_address.
Attributes inherited from PersonReference
Instance Method Summary collapse
- #get_import_rows ⇒ Object
-
#initialize(opt = nil) ⇒ Person
constructor
A new instance of Person.
- #parse_name_to_firstname_lastname_se(name, when_missing = '') ⇒ Object
- #serialize_name ⇒ Object
- #serialize_variables ⇒ Object
- #tags ⇒ Object
- #to_reference ⇒ Object
- #to_s ⇒ Object
- #validate ⇒ Object
- #with_postal_address {|@postal_address| ... } ⇒ Object
- #with_source {|@source| ... } ⇒ Object
Methods included from SerializeHelper
#serialize, #serialize_to_file
Methods included from ModelHasCustomFields
#set_custom_field, #set_custom_value
Methods included from ModelHasTags
Methods inherited from PersonReference
#empty?, from_person, #initalize
Constructor Details
#initialize(opt = nil) ⇒ Person
Returns a new instance of Person.
40 41 42 43 44 45 46 47 48 |
# File 'lib/fruit_to_lime/model/person.rb', line 40 def initialize(opt = nil) @currently_employed = true if opt != nil serialize_variables.each do |myattr| val = opt[myattr[:id]] instance_variable_set("@" + myattr[:id].to_s, val) if val != nil end end end |
Instance Attribute Details
#alternative_email ⇒ Object
Returns the value of attribute alternative_email.
33 34 35 |
# File 'lib/fruit_to_lime/model/person.rb', line 33 def alternative_email @alternative_email end |
#currently_employed ⇒ Object
Returns the value of attribute currently_employed.
33 34 35 |
# File 'lib/fruit_to_lime/model/person.rb', line 33 def currently_employed @currently_employed end |
#custom_values ⇒ Object (readonly)
you add custom values by using ModelHasCustomFields#set_custom_value
38 39 40 |
# File 'lib/fruit_to_lime/model/person.rb', line 38 def custom_values @custom_values end |
#direct_phone_number ⇒ Object
Returns the value of attribute direct_phone_number.
33 34 35 |
# File 'lib/fruit_to_lime/model/person.rb', line 33 def direct_phone_number @direct_phone_number end |
#email ⇒ Object
Returns the value of attribute email.
33 34 35 |
# File 'lib/fruit_to_lime/model/person.rb', line 33 def email @email end |
#fax_phone_number ⇒ Object
Returns the value of attribute fax_phone_number.
33 34 35 |
# File 'lib/fruit_to_lime/model/person.rb', line 33 def fax_phone_number @fax_phone_number end |
#first_name ⇒ Object
Returns the value of attribute first_name.
33 34 35 |
# File 'lib/fruit_to_lime/model/person.rb', line 33 def first_name @first_name end |
#home_phone_number ⇒ Object
Returns the value of attribute home_phone_number.
33 34 35 |
# File 'lib/fruit_to_lime/model/person.rb', line 33 def home_phone_number @home_phone_number end |
#last_name ⇒ Object
Returns the value of attribute last_name.
33 34 35 |
# File 'lib/fruit_to_lime/model/person.rb', line 33 def last_name @last_name end |
#mobile_phone_number ⇒ Object
Returns the value of attribute mobile_phone_number.
33 34 35 |
# File 'lib/fruit_to_lime/model/person.rb', line 33 def mobile_phone_number @mobile_phone_number end |
#organization ⇒ Object
you add custom values by using ModelHasCustomFields#set_custom_value
38 39 40 |
# File 'lib/fruit_to_lime/model/person.rb', line 38 def organization @organization end |
#position ⇒ Object
Returns the value of attribute position.
33 34 35 |
# File 'lib/fruit_to_lime/model/person.rb', line 33 def position @position end |
#postal_address ⇒ Object
Returns the value of attribute postal_address.
33 34 35 |
# File 'lib/fruit_to_lime/model/person.rb', line 33 def postal_address @postal_address end |
Instance Method Details
#get_import_rows ⇒ Object
117 118 119 120 121 |
# File 'lib/fruit_to_lime/model/person.rb', line 117 def get_import_rows (serialize_variables + [ { :id => :organization, :type => :organization_reference } ]).map do |p| map_to_row p end end |
#parse_name_to_firstname_lastname_se(name, when_missing = '') ⇒ Object
138 139 140 141 142 143 144 145 146 147 148 149 |
# File 'lib/fruit_to_lime/model/person.rb', line 138 def parse_name_to_firstname_lastname_se(name, when_missing = '') if name.nil? or name.empty? @first_name = when_missing return end splitted = name.split(' ') @first_name = splitted[0] if splitted.length > 1 @last_name = splitted.drop(1).join(' ') end end |
#serialize_name ⇒ Object
78 79 80 |
# File 'lib/fruit_to_lime/model/person.rb', line 78 def serialize_name "Person" end |
#serialize_variables ⇒ Object
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 |
# File 'lib/fruit_to_lime/model/person.rb', line 82 def serialize_variables [ {:id => :id, :type => :string}, {:id => :integration_id, :type => :string}, {:id => :source, :type => :source_ref}, {:id => :first_name, :type => :string}, {:id => :last_name, :type => :string}, {:id => :direct_phone_number, :type => :string}, {:id => :fax_phone_number, :type => :string}, {:id => :mobile_phone_number, :type => :string}, {:id => :home_phone_number, :type => :string}, {:id => :position, :type => :string}, {:id => :tags, :type => :tags}, {:id => :email, :type => :string}, {:id => :alternative_email, :type => :string}, {:id => :postal_address, :type => :address}, {:id => :custom_values, :type => :custom_values}, {:id => :currently_employed, :type => :bool}, {:id => :organization, :type => :organization_reference}, ] end |
#tags ⇒ Object
74 75 76 |
# File 'lib/fruit_to_lime/model/person.rb', line 74 def @tags end |
#to_reference ⇒ Object
110 111 112 113 114 115 |
# File 'lib/fruit_to_lime/model/person.rb', line 110 def to_reference() reference = PersonReference.new reference.id = @id reference.integration_id = @integration_id return reference end |
#to_s ⇒ Object
123 124 125 |
# File 'lib/fruit_to_lime/model/person.rb', line 123 def to_s return "#{first_name} #{last_name}" end |
#validate ⇒ Object
127 128 129 130 131 132 133 134 135 136 |
# File 'lib/fruit_to_lime/model/person.rb', line 127 def validate error = String.new if (@first_name.nil? || @first_name.empty?) && (@last_name.nil? || @last_name.empty?) error = "A firstname or lastname is required for person.\n#{serialize()}" end return error end |
#with_postal_address {|@postal_address| ... } ⇒ Object
59 60 61 62 |
# File 'lib/fruit_to_lime/model/person.rb', line 59 def with_postal_address @postal_address = Address.new if @postal_address == nil yield @postal_address end |
#with_source {|@source| ... } ⇒ Object
69 70 71 72 |
# File 'lib/fruit_to_lime/model/person.rb', line 69 def with_source @source = ReferenceToSource.new if @source == nil yield @source end |