Class: FruitToLime::Person

Inherits:
PersonReference show all
Includes:
ModelHasCustomFields, ModelHasTags, SerializeHelper
Defined in:
lib/fruit_to_lime/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
# File 'lib/fruit_to_lime/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
end

Instance Attribute Details

#alternative_emailObject

Returns the value of attribute alternative_email.



33
34
35
# File 'lib/fruit_to_lime/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/fruit_to_lime/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/fruit_to_lime/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/fruit_to_lime/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/fruit_to_lime/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/fruit_to_lime/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/fruit_to_lime/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/fruit_to_lime/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/fruit_to_lime/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/fruit_to_lime/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/fruit_to_lime/model/person.rb', line 38

def organization
  @organization
end

#positionObject

Returns the value of attribute position.



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

def position
  @position
end

#postal_addressObject

Returns the value of attribute postal_address.



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

def postal_address
  @postal_address
end

Instance Method Details

#get_import_rowsObject



117
118
119
120
121
# File 'lib/fruit_to_lime/model/person.rb', line 117

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



138
139
140
141
142
143
144
145
146
147
148
149
# File 'lib/fruit_to_lime/model/person.rb', line 138

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



78
79
80
# File 'lib/fruit_to_lime/model/person.rb', line 78

def serialize_name
    "Person"
end

#serialize_variablesObject



82
83
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
# File 'lib/fruit_to_lime/model/person.rb', line 82

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



74
75
76
# File 'lib/fruit_to_lime/model/person.rb', line 74

def tags
    @tags
end

#to_referenceObject



110
111
112
113
114
115
# File 'lib/fruit_to_lime/model/person.rb', line 110

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

#to_sObject



123
124
125
# File 'lib/fruit_to_lime/model/person.rb', line 123

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

#validateObject



127
128
129
130
131
132
133
134
135
136
# File 'lib/fruit_to_lime/model/person.rb', line 127

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:



59
60
61
62
# File 'lib/fruit_to_lime/model/person.rb', line 59

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:



69
70
71
72
# File 'lib/fruit_to_lime/model/person.rb', line 69

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