Class: BootstrapFormExtensions::Scheduler::Serializer
- Inherits:
-
Object
- Object
- BootstrapFormExtensions::Scheduler::Serializer
- Includes:
- Helpers
- Defined in:
- lib/bootstrap_form_extensions/scheduler.rb
Instance Attribute Summary collapse
-
#default_selection ⇒ Object
readonly
Returns the value of attribute default_selection.
-
#to_format ⇒ Object
readonly
Returns the value of attribute to_format.
Instance Method Summary collapse
- #dump(value_from_user) ⇒ Object
-
#initialize(to_format, default_selection) ⇒ Serializer
constructor
A new instance of Serializer.
- #load(value_from_db) ⇒ Object
Methods included from Helpers
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_selection ⇒ Object (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_format ⇒ Object (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 |