Class: GoImport::Person

Inherits:
PersonReference show all
Includes:
ModelHasCustomFields, ModelHasTags, SerializeHelper
Defined in:
lib/go_import/model/person.rb

Instance Attribute Summary collapse

Attributes inherited from PersonReference

#id, #integration_id

Instance Method Summary collapse

Methods included from SerializeHelper

#serialize, #serialize_to_file

Methods included from ModelHasCustomFields

#set_custom_field, #set_custom_value

Methods included from ModelHasTags

#set_tag

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_emailObject

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_employedObject

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_valuesObject (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_numberObject

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

#emailObject

Returns the value of attribute email.



33
34
35
# File 'lib/go_import/model/person.rb', line 33

def email
  @email
end

#fax_phone_numberObject

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_nameObject

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_numberObject

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_nameObject

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_numberObject

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

#organizationObject

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

#positionObject

Returns the value of attribute position.



33
34
35
# File 'lib/go_import/model/person.rb', line 33

def position
  @position
end

#postal_addressObject

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_rowsObject



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_nameObject



80
81
82
# File 'lib/go_import/model/person.rb', line 80

def serialize_name
    "Person"
end

#serialize_variablesObject



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

#tagsObject



76
77
78
# File 'lib/go_import/model/person.rb', line 76

def tags
    @tags
end

#to_referenceObject



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_sObject



125
126
127
# File 'lib/go_import/model/person.rb', line 125

def to_s
    return "#{first_name} #{last_name}"
end

#validateObject



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

Examples:

Set city of postal address to ‘Lund’

p.with_postal_address do |addr|
    addr.city = "Lund"
end

Yields:

See Also:



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

Examples:

Set the source to par id 4653

p.with_source do |source|
     source.par_se('4653')
end

Yields:

  • (@source)

See Also:



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