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).freeze
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
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
20 21 22 |
# File 'lib/axlsx/workbook/worksheet/auto_filter/filters.rb', line 20 def initialize( = {}) end |
Instance Attribute Details
#blank ⇒ Boolean
Flag indicating whether to filter by blank.
31 32 33 |
# File 'lib/axlsx/workbook/worksheet/auto_filter/filters.rb', line 31 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.
37 38 39 |
# File 'lib/axlsx/workbook/worksheet/auto_filter/filters.rb', line 37 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!
44 45 46 47 48 49 50 51 |
# File 'lib/axlsx/workbook/worksheet/auto_filter/filters.rb', line 44 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
59 60 61 |
# File 'lib/axlsx/workbook/worksheet/auto_filter/filters.rb', line 59 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.
102 103 104 105 106 107 108 |
# File 'lib/axlsx/workbook/worksheet/auto_filter/filters.rb', line 102 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
54 55 56 |
# File 'lib/axlsx/workbook/worksheet/auto_filter/filters.rb', line 54 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?)
92 93 94 95 96 |
# File 'lib/axlsx/workbook/worksheet/auto_filter/filters.rb', line 92 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
79 80 81 82 83 84 85 86 |
# File 'lib/axlsx/workbook/worksheet/auto_filter/filters.rb', line 79 def to_xml_string(str = +'') str << '<filters ' serialized_attributes(str) str << '>' 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 |