Class: GoImport::Organization
- Inherits:
-
CanBecomeImmutable
- Object
- CanBecomeImmutable
- GoImport::Organization
- Includes:
- ModelHasCustomFields, ModelHasTags, SerializeHelper
- Defined in:
- lib/go_import/model/organization.rb
Instance Attribute Summary collapse
-
#custom_values ⇒ Object
readonly
you add custom values by using ModelHasCustomFields#set_custom_value.
-
#employees ⇒ Object
readonly
Returns the value of attribute employees.
-
#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.
Attributes included from ModelHasTags
Instance Method Summary collapse
- #==(that) ⇒ Object
- #add_employee(val) ⇒ Object
- #find_employee_by_integration_id(integration_id) ⇒ Object
-
#initialize(opt = nil) ⇒ Organization
constructor
A new instance of Organization.
- #serialize_name ⇒ Object
- #serialize_variables ⇒ Object
- #to_reference ⇒ Object
- #to_s ⇒ Object
- #validate ⇒ Object
- #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.
63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/go_import/model/organization.rb', line 63 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? set_tag 'Import' end |
Instance Attribute Details
#custom_values ⇒ Object (readonly)
you add custom values by using ModelHasCustomFields#set_custom_value
61 62 63 |
# File 'lib/go_import/model/organization.rb', line 61 def custom_values @custom_values end |
#employees ⇒ Object (readonly)
Returns the value of attribute employees.
59 60 61 |
# File 'lib/go_import/model/organization.rb', line 59 def employees @employees end |
#relation ⇒ Object
Returns the value of attribute relation.
59 60 61 |
# File 'lib/go_import/model/organization.rb', line 59 def relation @relation end |
#relation_last_modified ⇒ Object
Sets/gets the date when this organization’s relation was changed. Default is Now.
57 58 59 |
# File 'lib/go_import/model/organization.rb', line 57 def relation_last_modified @relation_last_modified end |
#responsible_coworker ⇒ Object
Returns the value of attribute responsible_coworker.
59 60 61 |
# File 'lib/go_import/model/organization.rb', line 59 def responsible_coworker @responsible_coworker end |
Instance Method Details
#==(that) ⇒ Object
83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/go_import/model/organization.rb', line 83 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
134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 |
# File 'lib/go_import/model/organization.rb', line 134 def add_employee(val) @employees = [] if @employees == nil person = if val.is_a? Person then val else Person.new(val) end @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 |
#find_employee_by_integration_id(integration_id) ⇒ Object
188 189 190 191 192 193 |
# File 'lib/go_import/model/organization.rb', line 188 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_name ⇒ Object
216 217 218 |
# File 'lib/go_import/model/organization.rb', line 216 def serialize_name "Organization" end |
#serialize_variables ⇒ Object
195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 |
# File 'lib/go_import/model/organization.rb', line 195 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 |
#to_reference ⇒ Object
75 76 77 78 79 80 81 |
# File 'lib/go_import/model/organization.rb', line 75 def to_reference() reference = OrganizationReference.new reference.id = @id reference.integration_id = @integration_id reference.heading = @name return reference end |
#to_s ⇒ Object
220 221 222 |
# File 'lib/go_import/model/organization.rb', line 220 def to_s return "#{name}" end |
#validate ⇒ Object
224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 |
# File 'lib/go_import/model/organization.rb', line 224 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 |
#with_postal_address {|@postal_address| ... } ⇒ Object
100 101 102 103 |
# File 'lib/go_import/model/organization.rb', line 100 def with_postal_address @postal_address = Address.new if @postal_address == nil yield @postal_address end |
#with_source {|@source| ... } ⇒ Object
120 121 122 123 |
# File 'lib/go_import/model/organization.rb', line 120 def with_source @source = ReferenceToSource.new if @source == nil yield @source end |