class ActiveInteraction::AbstractDateTimeFilter
@abstract
Common logic for filters that handle ‘Date`, `DateTime`, and `Time`
objects.
@private
Public Instance Methods
accepts_grouped_inputs?()
click to toggle source
# File lib/active_interaction/filters/abstract_date_time_filter.rb, line 15 def accepts_grouped_inputs? true end
database_column_type()
click to toggle source
# File lib/active_interaction/filters/abstract_date_time_filter.rb, line 11 def database_column_type self.class.slug end
Private Instance Methods
convert(value)
click to toggle source
Calls superclass method
ActiveInteraction::Filter#convert
# File lib/active_interaction/filters/abstract_date_time_filter.rb, line 31 def convert(value) if value.respond_to?(:to_str) value = value.to_str if value.blank? send(__method__, nil) else [convert_string(value), nil] end elsif value.is_a?(GroupedInput) [convert_grouped_input(value), nil] else super end rescue NoMethodError # BasicObject super end
convert_grouped_input(value)
click to toggle source
# File lib/active_interaction/filters/abstract_date_time_filter.rb, line 58 def convert_grouped_input(value) date = %w[1 2 3].map { |key| value[key] }.join('-') time = %w[4 5 6].map { |key| value[key] }.join(':') convert_string("#{date} #{time}") end
convert_string(value)
click to toggle source
# File lib/active_interaction/filters/abstract_date_time_filter.rb, line 48 def convert_string(value) if format? klass.strptime(value, format) else klass.parse(value) || value end rescue ArgumentError value end
format()
click to toggle source
# File lib/active_interaction/filters/abstract_date_time_filter.rb, line 65 def format options.fetch(:format) end
format?()
click to toggle source
# File lib/active_interaction/filters/abstract_date_time_filter.rb, line 69 def format? options.key?(:format) end
klasses()
click to toggle source
# File lib/active_interaction/filters/abstract_date_time_filter.rb, line 21 def klasses [klass] end
matches?(value)
click to toggle source
# File lib/active_interaction/filters/abstract_date_time_filter.rb, line 25 def matches?(value) klasses.any? { |klass| value.is_a?(klass) } rescue NoMethodError # BasicObject false end