Class: Axlsx::FilterColumn

Inherits:
Object
  • Object
show all
Includes:
OptionsParser, SerializedAttributes
Defined in:
lib/axlsx/workbook/worksheet/auto_filter/filter_column.rb

Overview

The filterColumn collection identifies a particular column in the AutoFilter range and specifies filter information that has been applied to this column. If a column in the AutoFilter range has no criteria specified, then there is no corresponding filterColumn collection expressed for that column.

Constant Summary collapse

FILTERS =

Allowed filters

[:filters].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from SerializedAttributes

included, #serialized_attributes, #serialized_element_attributes, #serialized_tag

Methods included from OptionsParser

#parse_options

Constructor Details

#initialize(col_id, filter_type, options = {}) {|@filter| ... } ⇒ FilterColumn

Note:

This class yields its filter object as that is where the vast majority of processing will be done

Creates a new FilterColumn object

Parameters:

  • col_id (Integer|Cell)

    The zero based index for the column to which this filter will be applied

  • filter_type (Symbol)

    The symbolized class name of the filter to apply to this column.

  • options (Hash) (defaults to: {})

    options for this object and the filter

  • [Boolean] (Hash)

    a customizable set of options

Yields:



19
20
21
22
23
24
25
26
# File 'lib/axlsx/workbook/worksheet/auto_filter/filter_column.rb', line 19

def initialize(col_id, filter_type, options = {})
  RestrictionValidator.validate 'FilterColumn.filter', FILTERS, filter_type
  # Axlsx::validate_unsigned_int(col_id)
  self.col_id = col_id
  parse_options options
  @filter = Axlsx.const_get(Axlsx.camel(filter_type)).new(options)
  yield @filter if block_given?
end

Instance Attribute Details

#col_idInteger

Zero-based index indicating the AutoFilter column to which this filter information applies.

Returns:

  • (Integer)


35
36
37
# File 'lib/axlsx/workbook/worksheet/auto_filter/filter_column.rb', line 35

def col_id
  @col_id
end

#filterObject (readonly)

The actual filter being dealt with here This could be any one of the allowed filter types



39
40
41
# File 'lib/axlsx/workbook/worksheet/auto_filter/filter_column.rb', line 39

def filter
  @filter
end

Instance Method Details

#apply(row, offset) ⇒ Object

Apply the filters for this column filtered.

Parameters:

  • row (Array)

    A row from a worksheet that needs to be



70
71
72
# File 'lib/axlsx/workbook/worksheet/auto_filter/filter_column.rb', line 70

def apply(row, offset)
  row.hidden = @filter.apply(row.cells[offset + col_id.to_i])
end

#hidden_buttonBoolean

Flag indicating whether the AutoFilter button for this column is hidden.

Returns:

  • (Boolean)


53
54
55
# File 'lib/axlsx/workbook/worksheet/auto_filter/filter_column.rb', line 53

def hidden_button
  @hidden_button ||= false
end

#hidden_button=(hidden) ⇒ Boolean

Parameters:

  • hidden (Boolean)

    Flag indicating whether the AutoFilter button for this column is hidden.

Returns:

  • (Boolean)


76
77
78
79
# File 'lib/axlsx/workbook/worksheet/auto_filter/filter_column.rb', line 76

def hidden_button=(hidden)
  Axlsx.validate_boolean hidden
  @hidden_button = hidden
end

#show_buttonBoolean

Flag indicating whether the filter button is visible. When the cell containing the filter button is merged with another cell, the filter button can be hidden, and not drawn.

Returns:

  • (Boolean)


45
46
47
48
49
# File 'lib/axlsx/workbook/worksheet/auto_filter/filter_column.rb', line 45

def show_button
  return @show_button if defined?(@show_button)

  true
end

#show_button=(show) ⇒ Boolean

Flag indicating whether the AutoFilter button is show. This is undocumented in the spec, but exists in the schema file as an optional attribute.

Parameters:

  • show (Boolean)

    Show or hide the button

Returns:

  • (Boolean)


86
87
88
89
# File 'lib/axlsx/workbook/worksheet/auto_filter/filter_column.rb', line 86

def show_button=(show)
  Axlsx.validate_boolean show
  @show_button = show
end

#to_xml_string(str = +'')) ⇒ Object

Serialize the object to xml



92
93
94
95
96
97
98
# File 'lib/axlsx/workbook/worksheet/auto_filter/filter_column.rb', line 92

def to_xml_string(str = +'')
  str << '<filterColumn '
  serialized_attributes(str)
  str << '>'
  @filter.to_xml_string(str)
  str << "</filterColumn>"
end