Class: MoveToGo::Person

Inherits:
CanBecomeImmutable show all
Includes:
ModelHasCustomFields, ModelHasTags, SerializeHelper
Defined in:
lib/move-to-go/model/person.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from SerializeHelper

#serialize, #serialize_to_file

Methods included from ModelHasCustomFields

#set_custom_value

Methods included from ModelHasTags

#set_tag

Methods inherited from CanBecomeImmutable

immutable_accessor, #is_immutable, #raise_if_immutable, #set_is_immutable

Constructor Details

#initialize(opt = nil) ⇒ Person

Returns a new instance of Person.



86
87
88
89
90
91
92
93
94
95
96
# File 'lib/move-to-go/model/person.rb', line 86

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

#custom_valuesObject (readonly)

you add custom values by using ModelHasCustomFields#set_custom_value



84
85
86
# File 'lib/move-to-go/model/person.rb', line 84

def custom_values
  @custom_values
end

#organizationObject (readonly)

you add custom values by using ModelHasCustomFields#set_custom_value



84
85
86
# File 'lib/move-to-go/model/person.rb', line 84

def organization
  @organization
end

Instance Method Details

#alternative_emailObject

:attr_accessor: alternative_email



72
# File 'lib/move-to-go/model/person.rb', line 72

immutable_accessor :alternative_email

#currently_employedObject

:attr_accessor: currently_employed



78
# File 'lib/move-to-go/model/person.rb', line 78

immutable_accessor :currently_employed

#direct_phone_numberObject

:attr_accessor: direct_phone_number



54
# File 'lib/move-to-go/model/person.rb', line 54

immutable_accessor :direct_phone_number

#emailObject

:attr_accessor: email



69
# File 'lib/move-to-go/model/person.rb', line 69

immutable_accessor :email

#fax_phone_numberObject

:attr_accessor: fax_phone_number



57
# File 'lib/move-to-go/model/person.rb', line 57

immutable_accessor :fax_phone_number

#first_nameObject

:attr_accessor: first_name



48
# File 'lib/move-to-go/model/person.rb', line 48

immutable_accessor :first_name

#get_import_rowsObject



166
167
168
169
170
# File 'lib/move-to-go/model/person.rb', line 166

def get_import_rows
    (serialize_variables + [ { :id => :organization, :type => :organization_reference } ]).map do |p|
        map_to_row p
    end
end

:attr_accessor: has_mail_consent



81
# File 'lib/move-to-go/model/person.rb', line 81

immutable_accessor :has_mail_consent

#home_phone_numberObject

:attr_accessor: home_phone_number



63
# File 'lib/move-to-go/model/person.rb', line 63

immutable_accessor :home_phone_number

#idObject

:attr_accessor: id



42
# File 'lib/move-to-go/model/person.rb', line 42

immutable_accessor :id

#integration_idObject

:attr_accessor: integration_id



45
# File 'lib/move-to-go/model/person.rb', line 45

immutable_accessor :integration_id

#last_nameObject

:attr_accessor: last_name



51
# File 'lib/move-to-go/model/person.rb', line 51

immutable_accessor :last_name

#mobile_phone_numberObject

:attr_accessor: mobile_phone_number



60
# File 'lib/move-to-go/model/person.rb', line 60

immutable_accessor :mobile_phone_number

#parse_name_to_firstname_lastname_se(name, when_missing = '') ⇒ Object



187
188
189
190
191
192
193
194
195
196
197
198
# File 'lib/move-to-go/model/person.rb', line 187

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

#positionObject

:attr_accessor: position



66
# File 'lib/move-to-go/model/person.rb', line 66

immutable_accessor :position

#postal_addressObject

:attr_accessor: postal_address



75
# File 'lib/move-to-go/model/person.rb', line 75

immutable_accessor :postal_address

#serialize_nameObject



126
127
128
# File 'lib/move-to-go/model/person.rb', line 126

def serialize_name
    "Person"
end

#serialize_variablesObject



130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
# File 'lib/move-to-go/model/person.rb', line 130

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 => :has_mail_consent, :type => :bool},
     {:id => :organization, :type => :organization_reference},

    ]
end

#set_organization_reference=(org) ⇒ Object



98
99
100
# File 'lib/move-to-go/model/person.rb', line 98

def set_organization_reference=(org)
    @organization = OrganizationReference.from_organization(org)
end

#tagsObject



122
123
124
# File 'lib/move-to-go/model/person.rb', line 122

def tags
    @tags
end

#to_referenceObject



159
160
161
162
163
164
# File 'lib/move-to-go/model/person.rb', line 159

def to_reference()
    reference = PersonReference.new
    reference.id = @id
    reference.integration_id = @integration_id
    return reference
end

#to_sObject



172
173
174
# File 'lib/move-to-go/model/person.rb', line 172

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

#validateObject



176
177
178
179
180
181
182
183
184
185
# File 'lib/move-to-go/model/person.rb', line 176

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:



107
108
109
110
# File 'lib/move-to-go/model/person.rb', line 107

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:



117
118
119
120
# File 'lib/move-to-go/model/person.rb', line 117

def with_source
    @source = ReferenceToSource.new if @source == nil
    yield @source
end