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.



77
78
79
80
81
82
83
84
85
86
87
# File 'lib/move-to-go/model/person.rb', line 77

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



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

def custom_values
  @custom_values
end

#organizationObject (readonly)

you add custom values by using ModelHasCustomFields#set_custom_value



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

def organization
  @organization
end

Instance Method Details

#alternative_emailObject

:attr_accessor: alternative_email



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

immutable_accessor :alternative_email

#currently_employedObject

:attr_accessor: currently_employed



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

immutable_accessor :currently_employed

#direct_phone_numberObject

:attr_accessor: direct_phone_number



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

immutable_accessor :direct_phone_number

#emailObject

:attr_accessor: email



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

immutable_accessor :email

#fax_phone_numberObject

:attr_accessor: fax_phone_number



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

immutable_accessor :fax_phone_number

#first_nameObject

:attr_accessor: first_name



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

immutable_accessor :first_name

#get_import_rowsObject



156
157
158
159
160
# File 'lib/move-to-go/model/person.rb', line 156

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

#home_phone_numberObject

:attr_accessor: home_phone_number



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

immutable_accessor :home_phone_number

#idObject

:attr_accessor: id



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

immutable_accessor :id

#integration_idObject

:attr_accessor: integration_id



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

immutable_accessor :integration_id

#last_nameObject

:attr_accessor: last_name



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

immutable_accessor :last_name

#mobile_phone_numberObject

:attr_accessor: mobile_phone_number



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

immutable_accessor :mobile_phone_number

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



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

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



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

immutable_accessor :position

#postal_addressObject

:attr_accessor: postal_address



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

immutable_accessor :postal_address

#serialize_nameObject



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

def serialize_name
    "Person"
end

#serialize_variablesObject



121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
# File 'lib/move-to-go/model/person.rb', line 121

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

#set_organization_reference=(org) ⇒ Object



89
90
91
# File 'lib/move-to-go/model/person.rb', line 89

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

#tagsObject



113
114
115
# File 'lib/move-to-go/model/person.rb', line 113

def tags
    @tags
end

#to_referenceObject



149
150
151
152
153
154
# File 'lib/move-to-go/model/person.rb', line 149

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

#to_sObject



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

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

#validateObject



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

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:



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

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:



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

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