Class: MoveToGo::Coworker
Instance Method Summary
collapse
#get_import_rows, #serialize, #serialize_to_file
immutable_accessor, #is_immutable, #raise_if_immutable, #set_is_immutable
Constructor Details
#initialize(opt = nil) ⇒ Coworker
Returns a new instance of Coworker.
13
14
15
16
17
18
19
20
|
# File 'lib/move-to-go/model/coworker.rb', line 13
def initialize(opt = nil)
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 Method Details
#==(that) ⇒ Object
42
43
44
45
46
47
48
49
50
51
52
|
# File 'lib/move-to-go/model/coworker.rb', line 42
def ==(that)
if that.nil?
return false
end
if that.is_a? Coworker
return @integration_id == that.integration_id
end
return false
end
|
#guess_email(domain) ⇒ Object
71
72
73
74
75
76
77
78
|
# File 'lib/move-to-go/model/coworker.rb', line 71
def guess_email(domain)
return '' if @last_name.nil? || @last_name.empty?
return '' if @first_name.nil? || @first_name.empty?
firstname = to_email_chars @first_name.downcase
lastname = to_email_chars @last_name.downcase
return "#{firstname}.#{lastname}@#{domain}"
end
|
#parse_name_to_firstname_lastname_se(name, when_missing = '') ⇒ Object
54
55
56
57
58
59
60
61
62
63
64
65
|
# File 'lib/move-to-go/model/coworker.rb', line 54
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
38
39
40
|
# File 'lib/move-to-go/model/coworker.rb', line 38
def serialize_name
"Coworker"
end
|
#serialize_variables ⇒ Object
22
23
24
25
26
27
|
# File 'lib/move-to-go/model/coworker.rb', line 22
def serialize_variables
[
:id, :integration_id, :email, :first_name, :last_name,
:direct_phone_number, :mobile_phone_number, :home_phone_number
].map {|p| { :id => p, :type => :string } }
end
|
#to_email_chars(s) ⇒ Object
67
68
69
|
# File 'lib/move-to-go/model/coworker.rb', line 67
def to_email_chars(s)
s.tr " åäöèé", "-aaoee"
end
|
#to_reference ⇒ Object
29
30
31
32
33
34
35
36
|
# File 'lib/move-to-go/model/coworker.rb', line 29
def to_reference
reference = CoworkerReference.new
reference.id = @id
reference.integration_id = @integration_id
reference.heading = "#{@first_name} #{@last_name}".strip
return reference
end
|
#validate ⇒ Object
80
81
82
83
84
85
86
87
88
89
|
# File 'lib/move-to-go/model/coworker.rb', line 80
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 coworker.\n#{serialize()}"
end
return error
end
|