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 value.blank? ? send(__method__, nil) : convert_string(value) elsif value.is_a?(GroupedInput) convert_grouped_input(value) else super end rescue ArgumentError value rescue NoMethodError # BasicObject super end
convert_grouped_input(value)
click to toggle source
# File lib/active_interaction/filters/abstract_date_time_filter.rb, line 55 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 46 def convert_string(value) if format? klass.strptime(value, format) else klass.parse(value) || (raise ArgumentError, "no time information in #{value.inspect}") end end
format()
click to toggle source
# File lib/active_interaction/filters/abstract_date_time_filter.rb, line 62 def format options.fetch(:format) end
format?()
click to toggle source
# File lib/active_interaction/filters/abstract_date_time_filter.rb, line 66 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