Class: MoveToGo::Organization
- Inherits:
-
CanBecomeImmutable
- Object
- CanBecomeImmutable
- MoveToGo::Organization
- Includes:
- ModelHasCustomFields, ModelHasTags, SerializeHelper
- Defined in:
- lib/move-to-go/model/organization.rb
Instance Attribute Summary collapse
-
#custom_values ⇒ Object
readonly
you add custom values by using ModelHasCustomFields#set_custom_value.
-
#deals ⇒ Object
readonly
You can read linked objects.
-
#documents(type) ⇒ Object
readonly
You can read linked objects.
-
#employees ⇒ Object
readonly
Returns the value of attribute employees.
-
#histories ⇒ Object
readonly
You can read linked objects.
-
#relation ⇒ Object
Returns the value of attribute relation.
-
#relation_last_modified ⇒ Object
Sets/gets the date when this organization’s relation was changed.
-
#responsible_coworker ⇒ Object
Returns the value of attribute responsible_coworker.
-
#rootmodel ⇒ Object
Returns the value of attribute rootmodel.
Attributes included from ModelHasTags
Instance Method Summary collapse
- #==(that) ⇒ Object
- #add_employee(val) ⇒ Object
-
#central_phone_number ⇒ Object
:attr_accessor: central_phone_number.
-
#email ⇒ Object
:attr_accessor: email.
- #find_employee_by_integration_id(integration_id) ⇒ Object
-
#id ⇒ Object
:attr_accessor: id.
-
#initialize(opt = nil) ⇒ Organization
constructor
A new instance of Organization.
-
#integration_id ⇒ Object
:attr_accessor: integration_id.
- #meetings ⇒ Object
-
#move_data_from(org) ⇒ Object
Moves all data from an organization to this organization.
-
#name ⇒ Object
:attr_accessor: name.
-
#organization_number ⇒ Object
:attr_accessor: organization_number.
-
#postal_address ⇒ Object
:attr_accessor: postal_address.
- #serialize_name ⇒ Object
- #serialize_variables ⇒ Object
-
#source ⇒ Object
:attr_accessor: source.
-
#source_data ⇒ Object
:attr_accessor: source_data.
- #to_reference ⇒ Object
- #to_s ⇒ Object
- #todos ⇒ Object
- #validate ⇒ Object
-
#visit_address ⇒ Object
:attr_accessor: visit_address.
-
#web_site ⇒ Object
:attr_accessor: web_site.
- #with_postal_address {|@postal_address| ... } ⇒ Object
- #with_source {|@source| ... } ⇒ Object
- #with_visit_address {|@visit_address| ... } ⇒ Object
Methods included from SerializeHelper
#get_import_rows, #serialize, #serialize_to_file
Methods included from ModelHasCustomFields
Methods included from ModelHasTags
Methods inherited from CanBecomeImmutable
immutable_accessor, #is_immutable, #raise_if_immutable, #set_is_immutable
Constructor Details
#initialize(opt = nil) ⇒ Organization
Returns a new instance of Organization.
90 91 92 93 94 95 96 97 98 99 100 101 |
# File 'lib/move-to-go/model/organization.rb', line 90 def initialize(opt = nil) @employees = [] 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? set_tag 'Import' end |
Instance Attribute Details
#custom_values ⇒ Object (readonly)
you add custom values by using ModelHasCustomFields#set_custom_value
85 86 87 |
# File 'lib/move-to-go/model/organization.rb', line 85 def custom_values @custom_values end |
#deals ⇒ Object (readonly)
You can read linked objects
88 89 90 |
# File 'lib/move-to-go/model/organization.rb', line 88 def deals @deals end |
#documents(type) ⇒ Object (readonly)
You can read linked objects
88 89 90 |
# File 'lib/move-to-go/model/organization.rb', line 88 def documents @documents end |
#employees ⇒ Object (readonly)
Returns the value of attribute employees.
83 84 85 |
# File 'lib/move-to-go/model/organization.rb', line 83 def employees @employees end |
#histories ⇒ Object (readonly)
You can read linked objects
88 89 90 |
# File 'lib/move-to-go/model/organization.rb', line 88 def histories @histories end |
#relation ⇒ Object
Returns the value of attribute relation.
83 84 85 |
# File 'lib/move-to-go/model/organization.rb', line 83 def relation @relation end |
#relation_last_modified ⇒ Object
Sets/gets the date when this organization’s relation was changed. Default is Now.
81 82 83 |
# File 'lib/move-to-go/model/organization.rb', line 81 def relation_last_modified @relation_last_modified end |
#responsible_coworker ⇒ Object
Returns the value of attribute responsible_coworker.
83 84 85 |
# File 'lib/move-to-go/model/organization.rb', line 83 def responsible_coworker @responsible_coworker end |
#rootmodel ⇒ Object
Returns the value of attribute rootmodel.
77 78 79 |
# File 'lib/move-to-go/model/organization.rb', line 77 def rootmodel @rootmodel end |
Instance Method Details
#==(that) ⇒ Object
111 112 113 114 115 116 117 118 119 120 121 |
# File 'lib/move-to-go/model/organization.rb', line 111 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
162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 |
# File 'lib/move-to-go/model/organization.rb', line 162 def add_employee(val) @employees = [] if @employees == nil person = if val.is_a? Person then val else Person.new(val) end person.set_organization_reference = self @employees.push(person) # *** TODO: # # The person should be immutable after it has been added # to the organization. However most sources (LIME Easy, # LIME Pro, Excel, SalesForce, etc) are updating the # person after is has been added to the organization. We # must update the sources before we can set the person # immutable here. #person.set_is_immutable return person end |
#central_phone_number ⇒ Object
:attr_accessor: central_phone_number
70 |
# File 'lib/move-to-go/model/organization.rb', line 70 immutable_accessor :central_phone_number |
#email ⇒ Object
:attr_accessor: email
58 |
# File 'lib/move-to-go/model/organization.rb', line 58 immutable_accessor :email |
#find_employee_by_integration_id(integration_id) ⇒ Object
237 238 239 240 241 242 |
# File 'lib/move-to-go/model/organization.rb', line 237 def find_employee_by_integration_id(integration_id) return nil if @employees.nil? || integration_id.nil? return @employees.find do |e| e.integration_id == integration_id end end |
#id ⇒ Object
:attr_accessor: id
46 |
# File 'lib/move-to-go/model/organization.rb', line 46 immutable_accessor :id |
#integration_id ⇒ Object
:attr_accessor: integration_id
49 |
# File 'lib/move-to-go/model/organization.rb', line 49 immutable_accessor :integration_id |
#meetings ⇒ Object
203 204 205 |
# File 'lib/move-to-go/model/organization.rb', line 203 def meetings @rootmodel.select_meetings{|meeting| meeting.organization == self} end |
#move_data_from(org) ⇒ Object
Moves all data from an organization to this organization. The pillaged org is still kept as a empty shell of itself in the rootmodel
302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 |
# File 'lib/move-to-go/model/organization.rb', line 302 def move_data_from(org) flat_instance_variables_to_copy = [:@name, :@organization_number, :@email, :@web_site, :@central_phone_number] class_instance_variables_to_copy = [:@visiting_address, :@postal_address, :@source_data] org.instance_variables.each{ |variable| # Only change the value if it is empty if flat_instance_variables_to_copy.include? variable if !self.instance_variable_get(variable) self.instance_variable_set(variable, org.instance_variable_get(variable)) end # Some of the instances variabels are classes elsif class_instance_variables_to_copy.include? variable class_instance = org.instance_variable_get(variable) class_instance.instance_variables.each { |sub_variable| #If there is no class, create one if !self.instance_variable_get(variable) case variable when :@visit_address, :@postal_address klass = MoveToGo::Address.new when :@source_data klass = MoveToGo::SourceData.new end self.instance_variable_set(variable, klass) end if !self.instance_variable_get(variable).instance_variable_get(sub_variable) self.instance_variable_get(variable).instance_variable_set( sub_variable, class_instance.instance_variable_get(sub_variable) ) end } elsif variable == :@custom_values org.custom_values.each{ |custom_value| self.set_custom_value(custom_value.field, custom_value.value) } end } self.with_postal_address do end org.employees.each{ |person| self.add_employee(person)} org.deals.each{ |deal| deal.instance_variable_set("@customer", self)} # Object is "immutable" if using "=" org.histories.each{|history| history.instance_variable_set("@organization", self)} org.documents(:file).each{|file| file.instance_variable_set("@organization", self)} org.documents(:link).each{|history| history.instance_variable_set("@organization", self)} end |
#name ⇒ Object
:attr_accessor: name
52 |
# File 'lib/move-to-go/model/organization.rb', line 52 immutable_accessor :name |
#organization_number ⇒ Object
:attr_accessor: organization_number
55 |
# File 'lib/move-to-go/model/organization.rb', line 55 immutable_accessor :organization_number |
#postal_address ⇒ Object
:attr_accessor: postal_address
64 |
# File 'lib/move-to-go/model/organization.rb', line 64 immutable_accessor :postal_address |
#serialize_name ⇒ Object
265 266 267 |
# File 'lib/move-to-go/model/organization.rb', line 265 def serialize_name "Organization" end |
#serialize_variables ⇒ Object
244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 |
# File 'lib/move-to-go/model/organization.rb', line 244 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_reference, :type => :coworker_reference, :element_name => :responsible_coworker}, { :id => :relation, :type => :string }, { :id => :relation_last_modified, :type => :string } ] end |
#source ⇒ Object
:attr_accessor: source
73 |
# File 'lib/move-to-go/model/organization.rb', line 73 immutable_accessor :source |
#source_data ⇒ Object
:attr_accessor: source_data
76 |
# File 'lib/move-to-go/model/organization.rb', line 76 immutable_accessor :source_data |
#to_reference ⇒ Object
103 104 105 106 107 108 109 |
# File 'lib/move-to-go/model/organization.rb', line 103 def to_reference() reference = OrganizationReference.new reference.id = @id reference.integration_id = @integration_id reference.heading = @name return reference end |
#to_s ⇒ Object
269 270 271 |
# File 'lib/move-to-go/model/organization.rb', line 269 def to_s return "#{name}" end |
#todos ⇒ Object
199 200 201 |
# File 'lib/move-to-go/model/organization.rb', line 199 def todos @rootmodel.select_todos{|todo| todo.organization == self} end |
#validate ⇒ Object
273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 |
# File 'lib/move-to-go/model/organization.rb', line 273 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" elsif @source.id !~ /^\d{1}\d*:{1}\d{1}\d*$/ error = "#{error}\nInvalid source id '#{@source.id}', must have one ':' and only digits allowed, example '1:200010'" end end if @employees != nil @employees.each do |person| = person.validate() if !.empty? error = "#{error}\n#{}" end end end return error end |
#visit_address ⇒ Object
:attr_accessor: visit_address
67 |
# File 'lib/move-to-go/model/organization.rb', line 67 immutable_accessor :visit_address |
#web_site ⇒ Object
:attr_accessor: web_site
61 |
# File 'lib/move-to-go/model/organization.rb', line 61 immutable_accessor :web_site |
#with_postal_address {|@postal_address| ... } ⇒ Object
128 129 130 131 |
# File 'lib/move-to-go/model/organization.rb', line 128 def with_postal_address @postal_address = Address.new if @postal_address == nil yield @postal_address end |
#with_source {|@source| ... } ⇒ Object
148 149 150 151 |
# File 'lib/move-to-go/model/organization.rb', line 148 def with_source @source = ReferenceToSource.new if @source == nil yield @source end |