Class: FruitToLime::Organization

Inherits:
Object
  • Object
show all
Includes:
ModelHasCustomFields, ModelHasTags, SerializeHelper
Defined in:
lib/fruit_to_lime/model/organization.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from SerializeHelper

#get_import_rows, #serialize, #serialize_to_file

Methods included from ModelHasCustomFields

#set_custom_field, #set_custom_value

Methods included from ModelHasTags

#set_tag

Constructor Details

#initialize(opt = nil) ⇒ Organization

Returns a new instance of Organization.



55
56
57
58
59
60
61
62
63
64
# File 'lib/fruit_to_lime/model/organization.rb', line 55

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

    @relation = Relation::NoRelation if @relation.nil?
end

Instance Attribute Details

#central_phone_numberObject

Returns the value of attribute central_phone_number.



44
45
46
# File 'lib/fruit_to_lime/model/organization.rb', line 44

def central_phone_number
  @central_phone_number
end

#custom_valuesObject (readonly)

you add custom values by using ModelHasCustomFields#set_custom_value



53
54
55
# File 'lib/fruit_to_lime/model/organization.rb', line 53

def custom_values
  @custom_values
end

#emailObject

Returns the value of attribute email.



44
45
46
# File 'lib/fruit_to_lime/model/organization.rb', line 44

def email
  @email
end

#employeesObject (readonly)

Returns the value of attribute employees.



51
52
53
# File 'lib/fruit_to_lime/model/organization.rb', line 51

def employees
  @employees
end

#idObject

Returns the value of attribute id.



44
45
46
# File 'lib/fruit_to_lime/model/organization.rb', line 44

def id
  @id
end

#integration_idObject

Returns the value of attribute integration_id.



44
45
46
# File 'lib/fruit_to_lime/model/organization.rb', line 44

def integration_id
  @integration_id
end

#nameObject

Returns the value of attribute name.



44
45
46
# File 'lib/fruit_to_lime/model/organization.rb', line 44

def name
  @name
end

#organization_numberObject

Returns the value of attribute organization_number.



44
45
46
# File 'lib/fruit_to_lime/model/organization.rb', line 44

def organization_number
  @organization_number
end

#postal_addressObject

Returns the value of attribute postal_address.



44
45
46
# File 'lib/fruit_to_lime/model/organization.rb', line 44

def postal_address
  @postal_address
end

#relationObject

Returns the value of attribute relation.



51
52
53
# File 'lib/fruit_to_lime/model/organization.rb', line 51

def relation
  @relation
end

#relation_last_modifiedObject

Sets/gets the date when this organization’s relation was changed. Default is Now.



49
50
51
# File 'lib/fruit_to_lime/model/organization.rb', line 49

def relation_last_modified
  @relation_last_modified
end

#responsible_coworkerObject

Returns the value of attribute responsible_coworker.



51
52
53
# File 'lib/fruit_to_lime/model/organization.rb', line 51

def responsible_coworker
  @responsible_coworker
end

#source_dataObject

Returns the value of attribute source_data.



44
45
46
# File 'lib/fruit_to_lime/model/organization.rb', line 44

def source_data
  @source_data
end

#visit_addressObject

Returns the value of attribute visit_address.



44
45
46
# File 'lib/fruit_to_lime/model/organization.rb', line 44

def visit_address
  @visit_address
end

#web_siteObject

Returns the value of attribute web_site.



44
45
46
# File 'lib/fruit_to_lime/model/organization.rb', line 44

def web_site
  @web_site
end

Instance Method Details

#==(that) ⇒ Object



74
75
76
77
78
79
80
81
82
83
84
# File 'lib/fruit_to_lime/model/organization.rb', line 74

def ==(that)
    if that.nil?
        return false
    end

    if that.is_a? Organization
        return @integration_id == that.integration_id
    end

    return false
end

#add_employee(val) ⇒ Object

Examples:

Add an employee and then add additional info to that employee

employee = o.add_employee({
    :integration_id => "79654",
    :first_name => "Peter",
    :last_name => "Wilhelmsson"
})
employee.direct_phone_number = '+234234234'
employee.currently_employed = true

See Also:



125
126
127
128
129
130
# File 'lib/fruit_to_lime/model/organization.rb', line 125

def add_employee(val)
    @employees = [] if @employees == nil
    person = if val.is_a? Person then val else Person.new(val) end
    @employees.push(person)
    person
end

#find_employee_by_integration_id(integration_id) ⇒ Object



158
159
160
161
162
163
# File 'lib/fruit_to_lime/model/organization.rb', line 158

def find_employee_by_integration_id(integration_id)
    return nil if @employees.nil?
    return @employees.find do |e|
        e.integration_id == integration_id
    end
end

#serialize_nameObject



186
187
188
# File 'lib/fruit_to_lime/model/organization.rb', line 186

def serialize_name
    "Organization"
end

#serialize_variablesObject



165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
# File 'lib/fruit_to_lime/model/organization.rb', line 165

def serialize_variables
    [
     { :id => :id, :type => :string },
     { :id => :integration_id, :type => :string },
     { :id => :source, :type => :source_ref },
     { :id => :name, :type => :string },
     { :id => :organization_number, :type => :string },
     { :id => :postal_address, :type => :address },
     { :id => :visit_address, :type => :address },
     { :id => :central_phone_number, :type => :string },
     { :id => :email, :type => :string },
     { :id => :web_site, :type => :string },
     { :id => :employees, :type => :persons },
     { :id => :custom_values, :type => :custom_values },
     { :id => :tags, :type => :tags },
     { :id => :responsible_coworker, :type => :coworker_reference},
     { :id => :relation, :type => :string },
     { :id => :relation_last_modified, :type => :string }
    ]
end

#to_referenceObject



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

def to_reference()
    reference = OrganizationReference.new
    reference.id = @id
    reference.integration_id = @integration_id
    reference.heading = @name
    return reference
end

#to_sObject



190
191
192
# File 'lib/fruit_to_lime/model/organization.rb', line 190

def to_s
    return "#{name}"
end

#validateObject



194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
# File 'lib/fruit_to_lime/model/organization.rb', line 194

def validate
    error = String.new

    if @name.nil? || @name.empty?
        error = "A name is required for organization.\n#{serialize()}"
    end

    if !@source.nil?
        if @source.id.nil? || @source.id == ""
            error = "#{error}\nReference to source must have an id"
        end
    end

    if @employees != nil
        @employees.each do |person|
            validation_message = person.validate()
            if !validation_message.empty?
                error = "#{error}\n#{validation_message}"
            end
        end
    end

    return error
end

#with_postal_address {|@postal_address| ... } ⇒ Object

Examples:

Set city of postal address to ‘Lund’

o.with_postal_address do |addr|
    addr.city = "Lund"
end

Yields:

See Also:



91
92
93
94
# File 'lib/fruit_to_lime/model/organization.rb', line 91

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

o.with_source do |source|
     source.par_se('4653')
end

Yields:

  • (@source)

See Also:



111
112
113
114
# File 'lib/fruit_to_lime/model/organization.rb', line 111

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

#with_visit_address {|@visit_address| ... } ⇒ Object

Examples:

Set city of visit address to ‘Lund’

o.with_visit_address do |addr|
    addr.city = "Lund"
end

Yields:

See Also:



101
102
103
104
# File 'lib/fruit_to_lime/model/organization.rb', line 101

def with_visit_address
    @visit_address = Address.new if @visit_address == nil
    yield @visit_address
end