Class: MoveToGo::History

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

Direct Known Subclasses

ClientVisit, Comment, SalesCall, TalkedTo, TriedToReach

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) ⇒ History

Returns a new instance of History.



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

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

    @classification = HistoryClassification::Comment if @classification.nil?
end

Instance Attribute Details

#classificationObject

The history classification. It should be a value from #HistoryClassification. The default value is Comment.



19
20
21
# File 'lib/move-to-go/model/history.rb', line 19

def classification
  @classification
end

#created_byObject

Returns the value of attribute created_by.



15
16
17
# File 'lib/move-to-go/model/history.rb', line 15

def created_by
  @created_by
end

#dealObject

Returns the value of attribute deal.



15
16
17
# File 'lib/move-to-go/model/history.rb', line 15

def deal
  @deal
end

#organizationObject

Returns the value of attribute organization.



15
16
17
# File 'lib/move-to-go/model/history.rb', line 15

def organization
  @organization
end

#personObject

Returns the value of attribute person.



15
16
17
# File 'lib/move-to-go/model/history.rb', line 15

def person
  @person
end

#textObject

Returns the value of attribute text.



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

def text
  @text
end

Instance Method Details

#dateObject

:attr_accessor: date



12
# File 'lib/move-to-go/model/history.rb', line 12

immutable_accessor :date

#date=(date) ⇒ Object



133
134
135
# File 'lib/move-to-go/model/history.rb', line 133

def date=(date)
  @date = DateTime.parse(date)
end

#get_import_rowsObject



48
49
50
51
52
53
54
55
# File 'lib/move-to-go/model/history.rb', line 48

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/history.rb', line 6

immutable_accessor :id

#integration_idObject

:attr_accessor: integration_id



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

immutable_accessor :integration_id

#serialize_nameObject



57
58
59
# File 'lib/move-to-go/model/history.rb', line 57

def serialize_name
    "History"
end

#serialize_variablesObject



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/move-to-go/model/history.rb', line 32

def serialize_variables
    [ :id, :text, :integration_id, :classification ].map {
        |p| {
            :id => p,
            :type => :string
        }
    } +
        [
         { :id => :date, :type => :date },
         { :id => :created_by_reference, :type => :coworker_reference, :element_name => :created_by },
         { :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



137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
# File 'lib/move-to-go/model/history.rb', line 137

def validate
    error = String.new

    if (@classification.nil? || @classification.empty?)
        error = "Classification is required for history\n"
    end

    if (@text.nil? || @text.empty?) && classification != HistoryClassification::TriedToReach
        error = "Text is required for history\n"
    end

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

    if @organization.nil? && @deal.nil? && @person.nil?
        error = "#{error}Organization, deal or person is required for history\n"
    end

    return error
end