class Axlsx::Filters
When multiple values are chosen to filter by, or when a group of date values are chosen to filter by, this object groups those criteria together.
Constants
- CALENDAR_TYPES
Allowed calendar types
Attributes
Flag indicating whether to filter by blank. @return [Boolean]
Calendar type for date grouped items. Used to interpret the values in dateGroupItem. This is the calendar type used to evaluate all dates in the filter column, even when those dates are not using the same calendar system / date formatting.
Public Class Methods
Creates a new Filters
object @param [Hash] options Options used to set this objects attributes and
create filter and/or date group items
@option [Boolean] blank @see blank @option [String] calendar_type
@see calendar_type
@option [Array] filter_items
An array of values that will be used to create filter objects. @option [Array] date_group_items
An array of hases defining date group item filters to apply. @note The recommended way to interact with filter objects is via AutoFilter#add_column
@example
ws.auto_filter.add_column(0, :filters, :blank => true, :calendar_type => 'japan', :filter_items => [100, 'a'])
# File lib/axlsx/workbook/worksheet/auto_filter/filters.rb, line 19 def initialize(options={}) parse_options options end
Public Instance Methods
Tells us if the row of the cell provided should be filterd as it does not meet any of the specified filter_items
or date_group_items
restrictions. @param [Cell] cell The cell to test against items TODO implement this for date filters as well!
# File lib/axlsx/workbook/worksheet/auto_filter/filters.rb, line 43 def apply(cell) return false unless cell filter_items.each do |filter| return false if cell.value == filter.val end true end
Set the value for blank @see blank
# File lib/axlsx/workbook/worksheet/auto_filter/filters.rb, line 71 def blank=(use_blank) Axlsx.validate_boolean use_blank @blank = use_blank end
@see calendar_type
@param [String] calendar The calendar type to use. This must be one of the types defined in CALENDAR_TYPES
@return [String]
# File lib/axlsx/workbook/worksheet/auto_filter/filters.rb, line 64 def calendar_type=(calendar) RestrictionValidator.validate 'Filters.calendar_type', CALENDAR_TYPES, calendar @calendar_type = calendar end
the date group values in this filters object
# File lib/axlsx/workbook/worksheet/auto_filter/filters.rb, line 57 def date_group_items @date_group_items ||= [] end
Date group items are date group filter items where you specify the date_group and a value for that option as part of the auto_filter @note This can be specified, but will not be applied to the date values in your workbook at this time.
# File lib/axlsx/workbook/worksheet/auto_filter/filters.rb, line 98 def date_group_items=(options) options.each do |date_group| raise ArgumentError, "date_group_items should be an array of hashes specifying the options for each date_group_item" unless date_group.is_a?(Hash) date_group_items << DateGroupItem.new(date_group) end end
The filter values in this filters object
# File lib/axlsx/workbook/worksheet/auto_filter/filters.rb, line 52 def filter_items @filter_items ||= [] end
not entirely happy with this. filter_items
should be a simple typed list that overrides << etc to create Filter
objects from the inserted values. However this is most likely so rarely used…(really? do you know that?)
# File lib/axlsx/workbook/worksheet/auto_filter/filters.rb, line 88 def filter_items=(values) values.each do |value| filter_items << Filter.new(value) end end
Serialize the object to xml
# File lib/axlsx/workbook/worksheet/auto_filter/filters.rb, line 77 def to_xml_string(str = '') str << "<filters #{serialized_attributes}>" filter_items.each { |filter| filter.to_xml_string(str) } date_group_items.each { |date_group_item| date_group_item.to_xml_string(str) } str << '</filters>' end