Class: MoveToGo::Link

Inherits:
Object
  • Object
show all
Includes:
SerializeHelper
Defined in:
lib/move-to-go/model/link.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from SerializeHelper

#get_import_rows, #serialize, #serialize_to_file

Constructor Details

#initialize(opt = nil) ⇒ Link

Returns a new instance of Link.



8
9
10
11
12
13
14
15
# File 'lib/move-to-go/model/link.rb', line 8

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
end

Instance Attribute Details

#created_byObject

Returns the value of attribute created_by.



6
7
8
# File 'lib/move-to-go/model/link.rb', line 6

def created_by
  @created_by
end

#dealObject

Returns the value of attribute deal.



6
7
8
# File 'lib/move-to-go/model/link.rb', line 6

def deal
  @deal
end

#descriptionObject

Returns the value of attribute description.



4
5
6
# File 'lib/move-to-go/model/link.rb', line 4

def description
  @description
end

#idObject

Returns the value of attribute id.



4
5
6
# File 'lib/move-to-go/model/link.rb', line 4

def id
  @id
end

#integration_idObject

Returns the value of attribute integration_id.



4
5
6
# File 'lib/move-to-go/model/link.rb', line 4

def integration_id
  @integration_id
end

#nameObject

Returns the value of attribute name.



4
5
6
# File 'lib/move-to-go/model/link.rb', line 4

def name
  @name
end

#organizationObject

Returns the value of attribute organization.



6
7
8
# File 'lib/move-to-go/model/link.rb', line 6

def organization
  @organization
end

#personObject

Returns the value of attribute person.



6
7
8
# File 'lib/move-to-go/model/link.rb', line 6

def person
  @person
end

#urlObject

Returns the value of attribute url.



4
5
6
# File 'lib/move-to-go/model/link.rb', line 4

def url
  @url
end

Instance Method Details

#serialize_nameObject



17
18
19
# File 'lib/move-to-go/model/link.rb', line 17

def serialize_name
    "Link"
end

#serialize_variablesObject



21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/move-to-go/model/link.rb', line 21

def serialize_variables
    [ :id, :integration_id, :url, :name, :description ].map {
        |p| {
            :id => p,
            :type => :string
        }
    } +
        [
         { :id => :created_by_reference, :type => :coworker_reference, :element_name => :created_by },
         { :id => :organization_reference, :type => :organization_reference, :element_name => :organization },
         { :id => :person_reference, :type => :person_reference, :element_name => :person },
         { :id => :deal_reference, :type => :deal_reference, :element_name => :deal }
        ]
end

#validateObject



68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/move-to-go/model/link.rb', line 68

def validate
    error = String.new

    if @url.nil? || @url.empty?
        error = "Url is required for link\n"
    end

    if @created_by_reference.nil?
        error = "#{error}Created_by is required for link\n"
    end

    if @organization_reference.nil? && @deal_reference.nil? && @person_reference.nil?
        error = "#{error}A link must have either an organization, person or a deal\n"
    end

    return error
end