Class: FruitToLime::Note

Inherits:
Object
  • Object
show all
Includes:
SerializeHelper
Defined in:
lib/fruit_to_lime/model/note.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from SerializeHelper

#serialize, #serialize_to_file

Constructor Details

#initialize(opt = nil) ⇒ Note

Returns a new instance of Note.



12
13
14
15
16
17
18
19
20
21
# File 'lib/fruit_to_lime/model/note.rb', line 12

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 = NoteClassification::Comment if @classification.nil?
end

Instance Attribute Details

#classificationObject

The note’s classification. It should be a value from #NoteClassification. The default value is Comment.



10
11
12
# File 'lib/fruit_to_lime/model/note.rb', line 10

def classification
  @classification
end

#created_byObject

Returns the value of attribute created_by.



6
7
8
# File 'lib/fruit_to_lime/model/note.rb', line 6

def created_by
  @created_by
end

#dateObject

Returns the value of attribute date.



4
5
6
# File 'lib/fruit_to_lime/model/note.rb', line 4

def date
  @date
end

#dealObject

Returns the value of attribute deal.



6
7
8
# File 'lib/fruit_to_lime/model/note.rb', line 6

def deal
  @deal
end

#idObject

Returns the value of attribute id.



4
5
6
# File 'lib/fruit_to_lime/model/note.rb', line 4

def id
  @id
end

#integration_idObject

Returns the value of attribute integration_id.



4
5
6
# File 'lib/fruit_to_lime/model/note.rb', line 4

def integration_id
  @integration_id
end

#organizationObject

Returns the value of attribute organization.



6
7
8
# File 'lib/fruit_to_lime/model/note.rb', line 6

def organization
  @organization
end

#personObject

Returns the value of attribute person.



6
7
8
# File 'lib/fruit_to_lime/model/note.rb', line 6

def person
  @person
end

#textObject

Returns the value of attribute text.



4
5
6
# File 'lib/fruit_to_lime/model/note.rb', line 4

def text
  @text
end

Instance Method Details

#get_import_rowsObject



39
40
41
42
43
44
45
46
# File 'lib/fruit_to_lime/model/note.rb', line 39

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

#serialize_nameObject



48
49
50
# File 'lib/fruit_to_lime/model/note.rb', line 48

def serialize_name
    "Note"
end

#serialize_variablesObject



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/fruit_to_lime/model/note.rb', line 23

def serialize_variables
    [ :id, :text, :integration_id, :classification ].map {
        |p| {
            :id => p,
            :type => :string
        }
    } +
        [
         { :id => :date, :type => :date },
         { :id => :created_by, :type => :coworker_reference },
         { :id => :organization, :type => :organization_reference },
         { :id => :deal, :type => :deal_reference },
         { :id => :person, :type => :person_reference }
        ]
end

#validateObject



79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
# File 'lib/fruit_to_lime/model/note.rb', line 79

def validate
    error = String.new

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

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

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

    return error
end