Class: Axlsx::Filters::DateGroupItem

Inherits:
Object
  • Object
show all
Defined in:
lib/axlsx/workbook/worksheet/auto_filter/filters.rb

Overview

This collection is used to express a group of dates or times which are used in an AutoFilter criteria. Values are always written in the calendar type of the first date encountered in the filter range, so that all subsequent dates, even when formatted or represented by other calendar types, can be correctly compared for the purposes of filtering.

Constant Summary collapse

DATE_TIME_GROUPING =

Allowed date time groupings

%w(year month day hour minute second)

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ DateGroupItem

Creates a new DateGroupItem instanciating the object filter should apply for grouping

Parameters:

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

    A hash of options to use when

  • [String] (Hash)

    a customizable set of options

  • [Integer|String] (Hash)

    a customizable set of options

  • [Integer] (Hash)

    a customizable set of options

Raises:

  • (ArgumentError)


158
159
160
161
162
163
164
# File 'lib/axlsx/workbook/worksheet/auto_filter/filters.rb', line 158

def initialize(options={})
  raise ArgumentError,  "You must specify a year for date time grouping" unless options[:year]
  raise ArgumentError, "You must specify a date_time_grouping when creating a DateGroupItem for auto filter" unless options[:date_time_grouping]
  options.each do |key, value|
    self.send("#{key}=", value) if self.respond_to?("#{key}=")
  end
end

Instance Attribute Details

#date_time_groupingString

Grouping level This must be one of year, month, day, hour, minute or second.

Returns:

  • (String)


169
170
171
# File 'lib/axlsx/workbook/worksheet/auto_filter/filters.rb', line 169

def date_time_grouping
  @date_time_grouping
end

#dayInteger

Day (1-31)

Returns:

  • (Integer)


181
182
183
# File 'lib/axlsx/workbook/worksheet/auto_filter/filters.rb', line 181

def day
  @day
end

#hourInteger

Hour (0..23)

Returns:

  • (Integer)


185
186
187
# File 'lib/axlsx/workbook/worksheet/auto_filter/filters.rb', line 185

def hour
  @hour
end

#minuteInteger

Minute (0..59(

Returns:

  • (Integer)


189
190
191
# File 'lib/axlsx/workbook/worksheet/auto_filter/filters.rb', line 189

def minute
  @minute
end

#monthInteger

Month (1..12)

Returns:

  • (Integer)


177
178
179
# File 'lib/axlsx/workbook/worksheet/auto_filter/filters.rb', line 177

def month
  @month
end

#secondInteger

Second (0..59)

Returns:

  • (Integer)


193
194
195
# File 'lib/axlsx/workbook/worksheet/auto_filter/filters.rb', line 193

def second
  @second
end

#yearInteger|String

Year (4 digits)

Returns:

  • (Integer|String)


173
174
175
# File 'lib/axlsx/workbook/worksheet/auto_filter/filters.rb', line 173

def year
  @year
end

Instance Method Details

#to_xml_string(str = '') ⇒ Object

Serialize the object to xml

Parameters:

  • str (String) (defaults to: '')

    The string object this serialization will be concatenated to.



246
247
248
249
250
# File 'lib/axlsx/workbook/worksheet/auto_filter/filters.rb', line 246

def to_xml_string(str = '')
  str << '<dateGroupItem '
  instance_values.each { |key, value| str << "#{key}='#{value.to_s}' " }
  str << '/>'
end