Class: Axlsx::Filters
- Inherits:
-
Object
- Object
- Axlsx::Filters
- Includes:
- OptionsParser, SerializedAttributes
- Defined in:
- lib/axlsx/workbook/worksheet/auto_filter/filters.rb
Overview
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.
Defined Under Namespace
Classes: DateGroupItem, Filter
Constant Summary collapse
- CALENDAR_TYPES =
Allowed calendar types
%w(gregorian gregorianUs gregorianMeFrench gregorianArabic hijri hebrew taiwan japan thai korea saka gregorianXlitEnglish gregorianXlitFrench none)
Instance Attribute Summary collapse
-
#blank ⇒ Boolean
Flag indicating whether to filter by blank.
-
#calendar_type ⇒ Object
Calendar type for date grouped items.
Instance Method Summary collapse
-
#apply(cell) ⇒ Object
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.
-
#date_group_items ⇒ Object
the date group values in this filters object.
-
#date_group_items=(options) ⇒ Object
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 values in your workbook at this time.
-
#filter_items ⇒ Object
The filter values in this filters object.
-
#filter_items=(values) ⇒ Object
not entirely happy with this.
-
#initialize(options = {}) ⇒ Filters
constructor
Creates a new Filters object.
-
#to_xml_string(str = '') ⇒ Object
Serialize the object to xml.
Methods included from SerializedAttributes
#declared_attributes, included, #serialized_attributes, #serialized_element_attributes, #serialized_tag
Methods included from OptionsParser
Constructor Details
#initialize(options = {}) ⇒ Filters
The recommended way to interact with filter objects is via AutoFilter#add_column
Creates a new Filters object
19 20 21 |
# File 'lib/axlsx/workbook/worksheet/auto_filter/filters.rb', line 19 def initialize(={}) end |
Instance Attribute Details
#blank ⇒ Boolean
Flag indicating whether to filter by blank.
30 31 32 |
# File 'lib/axlsx/workbook/worksheet/auto_filter/filters.rb', line 30 def blank @blank end |
#calendar_type ⇒ Object
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.
36 37 38 |
# File 'lib/axlsx/workbook/worksheet/auto_filter/filters.rb', line 36 def calendar_type @calendar_type end |
Instance Method Details
#apply(cell) ⇒ Object
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. TODO implement this for date filters as well!
43 44 45 46 47 48 49 |
# 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 |
#date_group_items ⇒ Object
the date group values in this filters object
57 58 59 |
# File 'lib/axlsx/workbook/worksheet/auto_filter/filters.rb', line 57 def date_group_items @date_group_items ||= [] end |
#date_group_items=(options) ⇒ Object
This can be specified, but will not be applied to the date
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 values in your workbook at this time.
98 99 100 101 102 103 |
# File 'lib/axlsx/workbook/worksheet/auto_filter/filters.rb', line 98 def date_group_items=() .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 |
#filter_items ⇒ Object
The filter values in this filters object
52 53 54 |
# File 'lib/axlsx/workbook/worksheet/auto_filter/filters.rb', line 52 def filter_items @filter_items ||= [] end |
#filter_items=(values) ⇒ Object
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?)
88 89 90 91 92 |
# 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 |
#to_xml_string(str = '') ⇒ Object
Serialize the object to xml
77 78 79 80 81 82 |
# 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 |