Class: GoImport::Person
- Inherits:
-
PersonReference
- Object
- PersonReference
- GoImport::Person
- Includes:
- ModelHasCustomFields, ModelHasTags, SerializeHelper
- Defined in:
- lib/go_import/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 49 50 |
# File 'lib/go_import/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 set_tag 'Import' end |
Instance Attribute Details
#alternative_email ⇒ Object
Returns the value of attribute alternative_email.
33 34 35 |
# File 'lib/go_import/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/go_import/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/go_import/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/go_import/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/go_import/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/go_import/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/go_import/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/go_import/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/go_import/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/go_import/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/go_import/model/person.rb', line 38 def organization @organization end |
#position ⇒ Object
Returns the value of attribute position.
33 34 35 |
# File 'lib/go_import/model/person.rb', line 33 def position @position end |
#postal_address ⇒ Object
Returns the value of attribute postal_address.
33 34 35 |
# File 'lib/go_import/model/person.rb', line 33 def postal_address @postal_address end |
Instance Method Details
#get_import_rows ⇒ Object
119 120 121 122 123 |
# File 'lib/go_import/model/person.rb', line 119 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
140 141 142 143 144 145 146 147 148 149 150 151 |
# File 'lib/go_import/model/person.rb', line 140 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
80 81 82 |
# File 'lib/go_import/model/person.rb', line 80 def serialize_name "Person" end |
#serialize_variables ⇒ Object
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 109 110 |
# File 'lib/go_import/model/person.rb', line 84 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
76 77 78 |
# File 'lib/go_import/model/person.rb', line 76 def @tags end |
#to_reference ⇒ Object
112 113 114 115 116 117 |
# File 'lib/go_import/model/person.rb', line 112 def to_reference() reference = PersonReference.new reference.id = @id reference.integration_id = @integration_id return reference end |
#to_s ⇒ Object
125 126 127 |
# File 'lib/go_import/model/person.rb', line 125 def to_s return "#{first_name} #{last_name}" end |
#validate ⇒ Object
129 130 131 132 133 134 135 136 137 138 |
# File 'lib/go_import/model/person.rb', line 129 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
61 62 63 64 |
# File 'lib/go_import/model/person.rb', line 61 def with_postal_address @postal_address = Address.new if @postal_address == nil yield @postal_address end |
#with_source {|@source| ... } ⇒ Object
71 72 73 74 |
# File 'lib/go_import/model/person.rb', line 71 def with_source @source = ReferenceToSource.new if @source == nil yield @source end |