Module: Datagrid::Filters::InstanceMethods

Defined in:
lib/datagrid/filters.rb

Overview

ClassMethods

Instance Method Summary collapse

Instance Method Details

#assetsObject

:nodoc:


152
153
154
# File 'lib/datagrid/filters.rb', line 152

def assets # :nodoc:
  apply_filters(super, filters)
end

#default_filterObject


200
201
202
# File 'lib/datagrid/filters.rb', line 200

def default_filter
  self.class.default_filter
end

#filter_by(*filters) ⇒ Object

Returns assets filtered only by specified filters Allows partial filtering


179
180
181
# File 'lib/datagrid/filters.rb', line 179

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


173
174
175
# File 'lib/datagrid/filters.rb', line 173

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

#filter_value(filter) ⇒ Object

Returns filter value for given filter definition


157
158
159
# File 'lib/datagrid/filters.rb', line 157

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

#filter_value_as_string(name) ⇒ Object

Returns string representation of filter value


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

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


205
206
207
208
209
# File 'lib/datagrid/filters.rb', line 205

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

#initialize(*args, &block) ⇒ Object

:nodoc:


144
145
146
147
148
149
150
# File 'lib/datagrid/filters.rb', line 144

def initialize(*args, &block) # :nodoc:
  self.filters_array = self.class.filters_array.clone
  self.filters_array.each do |filter|
    self[filter.name] = filter.default(self)
  end
  super(*args, &block)
end

#select_all(filter) ⇒ Object

Sets all options as selected for a filter that has options


190
191
192
193
# File 'lib/datagrid/filters.rb', line 190

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`


185
186
187
# File 'lib/datagrid/filters.rb', line 185

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


196
197
198
# File 'lib/datagrid/filters.rb', line 196

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