module Golden::DatepickerConcern

Public Instance Methods

filter_dates_of_datepicker(fields, attrs) click to toggle source
# File lib/golden/active_model_concerns/datepicker_concern.rb, line 16
def filter_dates_of_datepicker(fields, attrs)
  fields.each do |field|
    dates = attrs.delete(field)
    attrs[field] = date_of_datepicker(dates)
  end
end
filter_duration_of_datepicker(field, attrs) click to toggle source
# File lib/golden/active_model_concerns/datepicker_concern.rb, line 23
def filter_duration_of_datepicker(field, attrs)
  return [] unless attrs.key? field

  dates = attrs.delete(field)
  duration_of_datepicker(dates)
end
permit_datepicker_of(fields, attrs) click to toggle source
# File lib/golden/active_model_concerns/datepicker_concern.rb, line 8
def permit_datepicker_of(fields, attrs)
  fields.each do |field|
    attrs.delete(field)
    attrs.push(field => [])
  end
end

Private Instance Methods

date_of_datepicker(values) click to toggle source
# File lib/golden/active_model_concerns/datepicker_concern.rb, line 32
def date_of_datepicker(values)
  values.is_a?(Array) ? (values.first || '') : values
end
duration_of_datepicker(values) click to toggle source
# File lib/golden/active_model_concerns/datepicker_concern.rb, line 36
def duration_of_datepicker(values)
  first_date = values.is_a?(Array) ? (values.first || '') : values
  last_date = values.is_a?(Array) && values.size > 1 ? (values.last || '') : ''
  [first_date, last_date]
end