Class: FlatKit::Stats
- Inherits:
-
Object
- Object
- FlatKit::Stats
- Includes:
- EventEmitter
- Defined in:
- lib/flat_kit/stats.rb
Overview
Internal: Collects stats from an Input and sends thos stats to an Output
Constant Summary collapse
- AllFields =
Class.new.freeze
Instance Attribute Summary collapse
-
#fields_to_stat ⇒ Object
readonly
Returns the value of attribute fields_to_stat.
-
#reader ⇒ Object
readonly
Returns the value of attribute reader.
-
#stats_by_field ⇒ Object
readonly
Returns the value of attribute stats_by_field.
-
#stats_to_collect ⇒ Object
readonly
Returns the value of attribute stats_to_collect.
-
#writer ⇒ Object
readonly
Returns the value of attribute writer.
Instance Method Summary collapse
- #call ⇒ Object
- #collecting_stats_on_field?(name) ⇒ Boolean
-
#initialize(input:, output:, input_fallback: "auto", output_fallback: "auto", fields_to_stat: AllFields, stats_to_collect: FieldStats::CORE_STATS) ⇒ Stats
constructor
A new instance of Stats.
Methods included from EventEmitter
#_listeners, #add_listener, #count_listeners, #notify_listeners, #remove_listener, #remove_listeners
Constructor Details
#initialize(input:, output:, input_fallback: "auto", output_fallback: "auto", fields_to_stat: AllFields, stats_to_collect: FieldStats::CORE_STATS) ⇒ Stats
Returns a new instance of Stats.
13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/flat_kit/stats.rb', line 13 def initialize(input:, output:, input_fallback: "auto", output_fallback: "auto", fields_to_stat: AllFields, stats_to_collect: FieldStats::CORE_STATS) @fields_to_stat = fields_to_stat @stats_to_collect = stats_to_collect @stats_by_field = {} @record_count = 0 @reader = ::FlatKit::Reader.create_reader_from_path(path: input, fallback: input_fallback) @writer = ::FlatKit::Writer.create_writer_from_path(path: output, fallback: output_fallback, reader_format: @reader.format_name) end |
Instance Attribute Details
#fields_to_stat ⇒ Object (readonly)
Returns the value of attribute fields_to_stat.
11 12 13 |
# File 'lib/flat_kit/stats.rb', line 11 def fields_to_stat @fields_to_stat end |
#reader ⇒ Object (readonly)
Returns the value of attribute reader.
11 12 13 |
# File 'lib/flat_kit/stats.rb', line 11 def reader @reader end |
#stats_by_field ⇒ Object (readonly)
Returns the value of attribute stats_by_field.
11 12 13 |
# File 'lib/flat_kit/stats.rb', line 11 def stats_by_field @stats_by_field end |
#stats_to_collect ⇒ Object (readonly)
Returns the value of attribute stats_to_collect.
11 12 13 |
# File 'lib/flat_kit/stats.rb', line 11 def stats_to_collect @stats_to_collect end |
#writer ⇒ Object (readonly)
Returns the value of attribute writer.
11 12 13 |
# File 'lib/flat_kit/stats.rb', line 11 def writer @writer end |
Instance Method Details
#call ⇒ Object
26 27 28 29 30 |
# File 'lib/flat_kit/stats.rb', line 26 def call calculate_stats write_stat_records @writer.close end |
#collecting_stats_on_field?(name) ⇒ Boolean
32 33 34 35 36 |
# File 'lib/flat_kit/stats.rb', line 32 def collecting_stats_on_field?(name) return true if @fields_to_stat == AllFields @fields_to_stat.include?(name) end |