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
43 44 45 46 47 48 |
# File 'app/models/import_document.rb', line 43 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
50 51 52 53 54 55 |
# File 'app/models/import_document.rb', line 50 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
33 34 35 36 37 38 39 40 41 |
# File 'app/models/import_document.rb', line 33 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 27 28 29 30 31 |
# 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 } # Set publication state if it exists in json_attributes if json_attributes["b1g_publication_state_s"].present? data_hash[:publication_state] = json_attributes["b1g_publication_state_s"] end append_created_at(data_hash) append_updated_at(data_hash) end |