Module: Labimotion::ConverterHelpers

Extended by:
Grape::API::Helpers
Defined in:
lib/labimotion/helpers/converter_helpers.rb

Overview

ConverterHelpers

Class Method Summary collapse

Class Method Details

.update_general_description(container, current_user, date: nil, time: nil) ⇒ Object

Update the general_description field in the container’s extended_metadata



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/labimotion/helpers/converter_helpers.rb', line 10

def self.update_general_description(container, current_user, date: nil, time: nil)
  return unless container.present?

  desc = container.['general_description']

  general_desc = desc if desc.present? && desc.is_a?(Hash)
  general_desc = JSON.parse(container.['general_description']) if desc.present? && desc.is_a?(String)
  general_desc = {} unless general_desc.is_a?(Hash)
  general_desc['creator'] = current_user.name if current_user.present?
  general_desc['date'] = date if date.present?
  general_desc['time'] = time if time.present?

  container.['general_description'] = general_desc.to_json
  container.save!
end