Class: BootstrapFormExtensions::Scheduler::Serializer

Inherits:
Object
  • Object
show all
Includes:
Helpers
Defined in:
lib/bootstrap_form_extensions/scheduler.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Helpers

#merge_css_classes, #true?

Constructor Details

#initialize(to_format, default_selection) ⇒ Serializer

Returns a new instance of Serializer.



42
43
44
45
# File 'lib/bootstrap_form_extensions/scheduler.rb', line 42

def initialize to_format, default_selection
  @to_format         = to_format
  @default_selection = default_selection
end

Instance Attribute Details

#default_selectionObject (readonly)

Returns the value of attribute default_selection.



40
41
42
# File 'lib/bootstrap_form_extensions/scheduler.rb', line 40

def default_selection
  @default_selection
end

#to_formatObject (readonly)

Returns the value of attribute to_format.



40
41
42
# File 'lib/bootstrap_form_extensions/scheduler.rb', line 40

def to_format
  @to_format
end

Instance Method Details

#dump(value_from_user) ⇒ Object



54
55
56
57
58
59
60
# File 'lib/bootstrap_form_extensions/scheduler.rb', line 54

def dump value_from_user
  value_from_user = JSON.parse value_from_user rescue [] if value_from_user.is_a? String
  value_from_user = [] unless value_from_user.is_a? Array
  value_from_user = parse_schedule_array value_from_user
  value_from_user = value_from_user.to_yaml if to_format == :yaml
  value_from_user
end

#load(value_from_db) ⇒ Object



47
48
49
50
51
52
# File 'lib/bootstrap_form_extensions/scheduler.rb', line 47

def load value_from_db
  value_from_db = YAML.load(value_from_db.to_s || '') if to_format == :yaml
  value_from_db = [] if value_from_db.blank?
  value_from_db = parse_schedule_array value_from_db unless value_from_db[6].try(:[], 23).present?
  value_from_db
end