Class: GoImport::History
- Inherits:
-
CanBecomeImmutable
- Object
- CanBecomeImmutable
- GoImport::History
- Includes:
- SerializeHelper
- Defined in:
- lib/go_import/model/history.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#classification ⇒ Object
The history classification.
-
#created_by ⇒ Object
Returns the value of attribute created_by.
-
#deal ⇒ Object
Returns the value of attribute deal.
-
#organization ⇒ Object
Returns the value of attribute organization.
-
#person ⇒ Object
Returns the value of attribute person.
-
#text ⇒ Object
Returns the value of attribute text.
Instance Method Summary collapse
- #get_import_rows ⇒ Object
-
#initialize(opt = nil) ⇒ History
constructor
A new instance of History.
- #serialize_name ⇒ Object
- #serialize_variables ⇒ Object
- #validate ⇒ Object
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.
15 16 17 18 19 20 21 22 23 24 |
# File 'lib/go_import/model/history.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 @classification = HistoryClassification::Comment if @classification.nil? end |
Instance Attribute Details
#classification ⇒ Object
The history classification. It should be a value from #HistoryClassification. The default value is Comment.
13 14 15 |
# File 'lib/go_import/model/history.rb', line 13 def classification @classification end |
#created_by ⇒ Object
Returns the value of attribute created_by.
9 10 11 |
# File 'lib/go_import/model/history.rb', line 9 def created_by @created_by end |
#deal ⇒ Object
Returns the value of attribute deal.
9 10 11 |
# File 'lib/go_import/model/history.rb', line 9 def deal @deal end |
#organization ⇒ Object
Returns the value of attribute organization.
9 10 11 |
# File 'lib/go_import/model/history.rb', line 9 def organization @organization end |
#person ⇒ Object
Returns the value of attribute person.
9 10 11 |
# File 'lib/go_import/model/history.rb', line 9 def person @person end |
#text ⇒ Object
Returns the value of attribute text.
8 9 10 |
# File 'lib/go_import/model/history.rb', line 8 def text @text end |
Instance Method Details
#get_import_rows ⇒ Object
42 43 44 45 46 47 48 49 |
# File 'lib/go_import/model/history.rb', line 42 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_name ⇒ Object
51 52 53 |
# File 'lib/go_import/model/history.rb', line 51 def serialize_name "History" end |
#serialize_variables ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/go_import/model/history.rb', line 26 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 |
#validate ⇒ Object
126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 |
# File 'lib/go_import/model/history.rb', line 126 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 |