class Sawmill::EntryProcessor::CountEntries

This processor reports the number of entries processed.

Public Class Methods

new(opts_={}) click to toggle source

Create a count-entries report.

Recognized options include:

:label

Label to use for the report. If provided, the report is returned as a string of the form “#{label}#{value}” If set to nil or absent, the report is returned as an integer.

:omit_unknown_data

If set to true, omits #unknown_data from the count. Default is false.

:omit_attributes

If set to true, omits attributes from the count. Default is false.

:omit_record_delimiters

If set to true, omits #begin_record and #end_record from the count. Default is false.

# File lib/sawmill/entry_processor/count_entries.rb, line 66
def initialize(opts_={})
  @label = opts_[:label]
  @omit_unknown_data = opts_[:omit_unknown_data]
  @omit_attributes = opts_[:omit_attributes]
  @omit_record_delimiters = opts_[:omit_record_delimiters]
  @finished = false
  @count = 0
end

Public Instance Methods

attribute(entry_) click to toggle source
# File lib/sawmill/entry_processor/count_entries.rb, line 91
def attribute(entry_)
  @count += 1 unless @finished || @omit_attributes
  true
end
begin_record(entry_) click to toggle source
# File lib/sawmill/entry_processor/count_entries.rb, line 76
def begin_record(entry_)
  @count += 1 unless @finished || @omit_record_delimiters
  true
end
end_record(entry_) click to toggle source
# File lib/sawmill/entry_processor/count_entries.rb, line 81
def end_record(entry_)
  @count += 1 unless @finished || @omit_record_delimiters
  true
end
finish() click to toggle source
# File lib/sawmill/entry_processor/count_entries.rb, line 101
def finish
  @finished = true
  @label ? "#{@label}#{@count}" : @count
end
message(entry_) click to toggle source
# File lib/sawmill/entry_processor/count_entries.rb, line 86
def message(entry_)
  @count += 1 unless @finished
  true
end
unknown_data(entry_) click to toggle source
# File lib/sawmill/entry_processor/count_entries.rb, line 96
def unknown_data(entry_)
  @count += 1 unless @finished || @omit_unknown_data
  true
end