lib/chronicle/etl/loaders/table_loader.rb in chronicle-etl-0.4.1 vs lib/chronicle/etl/loaders/table_loader.rb in chronicle-etl-0.4.2

- old
+ new

@@ -7,15 +7,14 @@ class TableLoader < Chronicle::ETL::Loader register_connector do |r| r.description = 'an ASCII table' end - setting :fields_limit, default: nil - setting :fields_exclude, default: ['lids', 'type'] - setting :fields, default: [] setting :truncate_values_at, default: 40 setting :table_renderer, default: :basic + setting :fields_exclude, default: ['lids', 'type'] + setting :header_row, default: true def load(record) records << record.to_h_flattened end @@ -23,11 +22,11 @@ return if records.empty? headers = build_headers(records) rows = build_rows(records, headers) - @table = TTY::Table.new(header: headers, rows: rows) + @table = TTY::Table.new(header: (headers if @config.header_row), rows: rows) puts @table.render( @config.table_renderer.to_sym, padding: [0, 2, 0, 0] ) end @@ -36,28 +35,13 @@ @records ||= [] end private - def build_headers(records) - headers = - if @config.fields.any? - Set[*@config.fields] - else - # use all the keys of the flattened record hash - Set[*records.map(&:keys).flatten.map(&:to_s).uniq] - end - - headers = headers.delete_if { |header| header.end_with?(*@config.fields_exclude) } if @config.fields_exclude.any? - headers = headers.first(@config.fields_limit) if @config.fields_limit - - headers.to_a.map(&:to_sym) - end - def build_rows(records, headers) records.map do |record| values = record.transform_keys(&:to_sym).values_at(*headers).map{|value| value.to_s } - + values = values.map { |value| force_utf8(value) } if @config.truncate_values_at values = values.map{ |value| value.truncate(@config.truncate_values_at) } end values