Sha256: 7e6325359b69c571bc21a8105f47bf1c0e347c309af4ffda1dd7a1a31c1c088a
Contents?: true
Size: 904 Bytes
Versions: 1
Compression:
Stored size: 904 Bytes
Contents
# @!visibility private class Datagrid::Filters::ExtendedBooleanFilter < Datagrid::Filters::EnumFilter YES = "YES" NO = "NO" TRUTH_VALUES = [true, 'true', "y", "yes"] FALSE_VALUES = [false, 'false', "n", "no"] def initialize(report, attribute, options = {}, &block) options[:select] = -> { boolean_select } super(report, attribute, options, &block) end def execute(value, scope, grid_object) value = value.blank? ? nil : ::Datagrid::Utils.booleanize(value) super(value, scope, grid_object) end def parse(value) value = value.downcase if value.is_a?(String) case value when *TRUTH_VALUES YES when *FALSE_VALUES NO when value.blank? nil else super(value) end end protected def boolean_select [YES, NO].map do |key, value| [I18n.t("datagrid.filters.xboolean.#{key.downcase}"), key] end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
datagrid-1.8.2 | lib/datagrid/filters/extended_boolean_filter.rb |