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.
-
#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_data ⇒ Object
:attr_accessor: source_data.
- #to_reference ⇒ Object
- #to_s ⇒ 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.
87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/move-to-go/model/organization.rb', line 87 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
82 83 84 |
# File 'lib/move-to-go/model/organization.rb', line 82 def custom_values @custom_values end |
#deals ⇒ Object (readonly)
You can read linked objects
85 86 87 |
# File 'lib/move-to-go/model/organization.rb', line 85 def deals @deals end |
#documents(type) ⇒ Object (readonly)
You can read linked objects
85 86 87 |
# File 'lib/move-to-go/model/organization.rb', line 85 def documents @documents end |
#employees ⇒ Object (readonly)
Returns the value of attribute employees.
80 81 82 |
# File 'lib/move-to-go/model/organization.rb', line 80 def employees @employees end |
#histories ⇒ Object (readonly)
You can read linked objects
85 86 87 |
# File 'lib/move-to-go/model/organization.rb', line 85 def histories @histories end |
#relation ⇒ Object
Returns the value of attribute relation.
80 81 82 |
# File 'lib/move-to-go/model/organization.rb', line 80 def relation @relation end |
#relation_last_modified ⇒ Object
Sets/gets the date when this organization’s relation was changed. Default is Now.
78 79 80 |
# File 'lib/move-to-go/model/organization.rb', line 78 def relation_last_modified @relation_last_modified end |
#responsible_coworker ⇒ Object
Returns the value of attribute responsible_coworker.
80 81 82 |
# File 'lib/move-to-go/model/organization.rb', line 80 def responsible_coworker @responsible_coworker end |
#rootmodel ⇒ Object
Returns the value of attribute rootmodel.
74 75 76 |
# File 'lib/move-to-go/model/organization.rb', line 74 def rootmodel @rootmodel end |
Instance Method Details
#==(that) ⇒ Object
108 109 110 111 112 113 114 115 116 117 118 |
# File 'lib/move-to-go/model/organization.rb', line 108 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
159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 |
# File 'lib/move-to-go/model/organization.rb', line 159 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
226 227 228 229 230 231 |
# File 'lib/move-to-go/model/organization.rb', line 226 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 |
#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 |
#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
289 290 291 292 293 294 295 296 297 298 299 300 301 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 |
# File 'lib/move-to-go/model/organization.rb', line 289 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
254 255 256 |
# File 'lib/move-to-go/model/organization.rb', line 254 def serialize_name "Organization" end |
#serialize_variables ⇒ Object
233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 |
# File 'lib/move-to-go/model/organization.rb', line 233 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_data ⇒ Object
:attr_accessor: source_data
73 |
# File 'lib/move-to-go/model/organization.rb', line 73 immutable_accessor :source_data |
#to_reference ⇒ Object
100 101 102 103 104 105 106 |
# File 'lib/move-to-go/model/organization.rb', line 100 def to_reference() reference = OrganizationReference.new reference.id = @id reference.integration_id = @integration_id reference.heading = @name return reference end |
#to_s ⇒ Object
258 259 260 |
# File 'lib/move-to-go/model/organization.rb', line 258 def to_s return "#{name}" end |
#validate ⇒ Object
262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 |
# File 'lib/move-to-go/model/organization.rb', line 262 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| = 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
125 126 127 128 |
# File 'lib/move-to-go/model/organization.rb', line 125 def with_postal_address @postal_address = Address.new if @postal_address == nil yield @postal_address end |
#with_source {|@source| ... } ⇒ Object
145 146 147 148 |
# File 'lib/move-to-go/model/organization.rb', line 145 def with_source @source = ReferenceToSource.new if @source == nil yield @source end |