Class: ImportDocument
- Inherits:
-
ApplicationRecord
- Object
- ActiveRecord::Base
- ApplicationRecord
- ImportDocument
- Defined in:
- app/models/import_document.rb
Overview
ImportDocument class
Instance Method Summary collapse
- #append_created_at(data_hash) ⇒ Object
- #append_updated_at(data_hash) ⇒ Object
- #nullify_empty_json_attributes ⇒ Object
- #state_machine ⇒ Object
- #to_hash ⇒ Object
Instance Method Details
#append_created_at(data_hash) ⇒ Object
38 39 40 41 42 43 |
# File 'app/models/import_document.rb', line 38 def append_created_at(data_hash) if data_hash[:json_attributes].has_key?("date_created_dtsi") data_hash[:created_at] = data_hash[:json_attributes]["date_created_dtsi"] end data_hash end |
#append_updated_at(data_hash) ⇒ Object
45 46 47 48 49 50 |
# File 'app/models/import_document.rb', line 45 def append_updated_at(data_hash) if data_hash[:json_attributes].has_key?("date_modified_dtsi") data_hash[:updated_at] = data_hash[:json_attributes]["date_modified_dtsi"] end data_hash end |
#nullify_empty_json_attributes ⇒ Object
28 29 30 31 32 33 34 35 36 |
# File 'app/models/import_document.rb', line 28 def nullify_empty_json_attributes clean_hash = {} json_attributes.each do |key, value| clean_hash[key] = value.present? ? value : nil end clean_hash end |
#state_machine ⇒ Object
12 13 14 |
# File 'app/models/import_document.rb', line 12 def state_machine @state_machine ||= ImportDocumentStateMachine.new(self, transition_class: ImportDocumentTransition) end |
#to_hash ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 |
# File 'app/models/import_document.rb', line 16 def to_hash data_hash = { friendlier_id: friendlier_id, title: title, json_attributes: nullify_empty_json_attributes, import_id: import_id } append_created_at(data_hash) append_updated_at(data_hash) end |