Class: MoveToGo::Todo

Inherits:
CanBecomeImmutable show all
Includes:
SerializeHelper
Defined in:
lib/move-to-go/model/todo.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from SerializeHelper

#serialize, #serialize_to_file

Methods inherited from CanBecomeImmutable

immutable_accessor, #is_immutable, #raise_if_immutable, #set_is_immutable

Constructor Details

#initialize(opt = nil) ⇒ Todo

Returns a new instance of Todo.



15
16
17
18
19
20
21
22
# File 'lib/move-to-go/model/todo.rb', line 15

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

#assigned_coworkerObject

Returns the value of attribute assigned_coworker.



13
14
15
# File 'lib/move-to-go/model/todo.rb', line 13

def assigned_coworker
  @assigned_coworker
end

#created_byObject

Returns the value of attribute created_by.



13
14
15
# File 'lib/move-to-go/model/todo.rb', line 13

def created_by
  @created_by
end

#date_checkedObject

Returns the value of attribute date_checked.



12
13
14
# File 'lib/move-to-go/model/todo.rb', line 12

def date_checked
  @date_checked
end

#date_startObject

Returns the value of attribute date_start.



12
13
14
# File 'lib/move-to-go/model/todo.rb', line 12

def date_start
  @date_start
end

#date_start_has_timeObject

Returns the value of attribute date_start_has_time.



12
13
14
# File 'lib/move-to-go/model/todo.rb', line 12

def date_start_has_time
  @date_start_has_time
end

#dealObject

Returns the value of attribute deal.



13
14
15
# File 'lib/move-to-go/model/todo.rb', line 13

def deal
  @deal
end

#organizationObject

Returns the value of attribute organization.



13
14
15
# File 'lib/move-to-go/model/todo.rb', line 13

def organization
  @organization
end

#personObject

Returns the value of attribute person.



13
14
15
# File 'lib/move-to-go/model/todo.rb', line 13

def person
  @person
end

#textObject

Returns the value of attribute text.



11
12
13
# File 'lib/move-to-go/model/todo.rb', line 11

def text
  @text
end

Instance Method Details

#get_import_rowsObject



43
44
45
46
47
48
49
50
# File 'lib/move-to-go/model/todo.rb', line 43

def get_import_rows
    (serialize_variables + [
        { :id => :organization, :type => :organization_reference},
        { :id => :person, :type => :person_reference}
        ]).map do |p|
        map_to_row p
    end
end

#idObject

:attr_accessor: id



6
# File 'lib/move-to-go/model/todo.rb', line 6

immutable_accessor :id

#integration_idObject

:attr_accessor: integration_id



9
# File 'lib/move-to-go/model/todo.rb', line 9

immutable_accessor :integration_id

#serialize_nameObject



52
53
54
# File 'lib/move-to-go/model/todo.rb', line 52

def serialize_name
    "Todo"
end

#serialize_variablesObject



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/move-to-go/model/todo.rb', line 24

def serialize_variables
    [ :id, :text, :integration_id ].map {
        |p| {
            :id => p,
            :type => :string
        }
    } +
        [
         { :id => :date_start, :type => :datetime },
         { :id => :date_start_has_time, :type => :bool },
         { :id => :date_checked, :type => :datetime },
         { :id => :created_by_reference, :type => :coworker_reference, :element_name => :created_by },
         { :id => :assigned_coworker_reference, :type => :coworker_reference, :element_name => :assigned_coworker },
         { :id => :organization_reference, :type => :organization_reference, :element_name => :organization },
         { :id => :deal_reference, :type => :deal_reference, :element_name => :deal },
         { :id => :person_reference, :type => :person_reference, :element_name => :person }
        ]
end

#validateObject



152
153
154
155
156
157
158
159
160
161
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/todo.rb', line 152

def validate
    error = String.new

    if (@text.nil? || @text.empty?)
        error = "Text is required for todo\n"
    end

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

    if @assigned_coworker_reference.nil?
        error = "#{error}Assigned_coworker is required for todo\n"
    end

    if @date_start.nil?
        error = "#{error}Date_start is required for todo\n"
    end

    if @date_start_has_time.nil?
        error = "#{error}Date_start_has_time is required for todo\n"
    end

    if @organization.nil?
        error = "#{error}Organization is required for todo\n"
    end

    return error
end