Class: FruitToLime::Coworker

Inherits:
Object
  • Object
show all
Includes:
SerializeHelper
Defined in:
lib/fruit_to_lime/model/coworker.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from SerializeHelper

#get_import_rows, #serialize, #serialize_to_file

Constructor Details

#initialize(opt = nil) ⇒ Coworker

Returns a new instance of Coworker.



8
9
10
11
12
13
14
15
# File 'lib/fruit_to_lime/model/coworker.rb', line 8

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 Attribute Details

#direct_phone_numberObject

Returns the value of attribute direct_phone_number.



5
6
7
# File 'lib/fruit_to_lime/model/coworker.rb', line 5

def direct_phone_number
  @direct_phone_number
end

#emailObject

Returns the value of attribute email.



5
6
7
# File 'lib/fruit_to_lime/model/coworker.rb', line 5

def email
  @email
end

#first_nameObject

Returns the value of attribute first_name.



5
6
7
# File 'lib/fruit_to_lime/model/coworker.rb', line 5

def first_name
  @first_name
end

#home_phone_numberObject

Returns the value of attribute home_phone_number.



5
6
7
# File 'lib/fruit_to_lime/model/coworker.rb', line 5

def home_phone_number
  @home_phone_number
end

#idObject

Returns the value of attribute id.



5
6
7
# File 'lib/fruit_to_lime/model/coworker.rb', line 5

def id
  @id
end

#integration_idObject

Returns the value of attribute integration_id.



5
6
7
# File 'lib/fruit_to_lime/model/coworker.rb', line 5

def integration_id
  @integration_id
end

#last_nameObject

Returns the value of attribute last_name.



5
6
7
# File 'lib/fruit_to_lime/model/coworker.rb', line 5

def last_name
  @last_name
end

#mobile_phone_numberObject

Returns the value of attribute mobile_phone_number.



5
6
7
# File 'lib/fruit_to_lime/model/coworker.rb', line 5

def mobile_phone_number
  @mobile_phone_number
end

Instance Method Details

#==(that) ⇒ Object



37
38
39
40
41
42
43
44
45
46
47
# File 'lib/fruit_to_lime/model/coworker.rb', line 37

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



66
67
68
69
70
71
72
73
# File 'lib/fruit_to_lime/model/coworker.rb', line 66

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



49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/fruit_to_lime/model/coworker.rb', line 49

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



33
34
35
# File 'lib/fruit_to_lime/model/coworker.rb', line 33

def serialize_name
    "Coworker"
end

#serialize_variablesObject



17
18
19
20
21
22
# File 'lib/fruit_to_lime/model/coworker.rb', line 17

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



62
63
64
# File 'lib/fruit_to_lime/model/coworker.rb', line 62

def to_email_chars(s)
    s.tr " åäöèé", "-aaoee"
end

#to_referenceObject



24
25
26
27
28
29
30
31
# File 'lib/fruit_to_lime/model/coworker.rb', line 24

def to_reference
    reference = CoworkerReference.new
    reference.id = @id
    reference.integration_id = @integration_id
    reference.heading = "#{@first_name} #{@last_name}".strip

    return reference
end