Module: Datagrid::Filters::InstanceMethods

Defined in:
lib/datagrid/filters.rb

Instance Method Summary collapse

Instance Method Details

#default_filterObject



202
203
204
# File 'lib/datagrid/filters.rb', line 202

def default_filter
  self.class.default_filter
end

#filter_by(*filters) ⇒ Object

Returns assets filtered only by specified filters Allows partial filtering



181
182
183
# File 'lib/datagrid/filters.rb', line 181

def filter_by(*filters)
  apply_filters(scope, filters.map{|f| filter_by_name(f)})
end

#filter_by_name(name) ⇒ Object

Returns filter object with the given name



175
176
177
# File 'lib/datagrid/filters.rb', line 175

def filter_by_name(name)
  self.class.filter_by_name(name)
end

#filter_value(filter) ⇒ Object

Returns filter value for given filter definition



159
160
161
# File 'lib/datagrid/filters.rb', line 159

def filter_value(filter)
  self[filter.name]
end

#filter_value_as_string(name) ⇒ Object

Returns string representation of filter value



164
165
166
167
168
169
170
171
172
# File 'lib/datagrid/filters.rb', line 164

def filter_value_as_string(name)
  filter = filter_by_name(name)
  value = filter_value(filter)
  if value.is_a?(Array)
    value.map {|v| filter.format(v) }.join(filter.separator)
  else
    filter.format(value)
  end
end

#filtersObject

Returns all currently enabled filters



207
208
209
210
211
# File 'lib/datagrid/filters.rb', line 207

def filters
  self.class.filters.select do |filter|
    filter.enabled?(self)
  end
end

#select_all(filter) ⇒ Object

Sets all options as selected for a filter that has options



192
193
194
195
# File 'lib/datagrid/filters.rb', line 192

def select_all(filter)
  filter = find_select_filter(filter)
  self[filter.name] = select_values(filter)
end

#select_options(filter) ⇒ Object

Returns select options for specific filter or filter name If given filter doesn’t support select options raises ‘ArgumentError`



187
188
189
# File 'lib/datagrid/filters.rb', line 187

def select_options(filter)
  find_select_filter(filter).select(self)
end

#select_values(filter) ⇒ Object

Returns all values that can be set to a filter with select options



198
199
200
# File 'lib/datagrid/filters.rb', line 198

def select_values(filter)
  find_select_filter(filter).select_values(self)
end