Sha256: fd0505579360d9dab0add55f2b0208eafdff4e72fdb34d2381982bff39cac5f8

Contents?: true

Size: 422 Bytes

Versions: 8

Compression:

Stored size: 422 Bytes

Contents

class ConsoleFormatter < Struct.new :format

  def present records, format = format
    Hirb::Helpers::AutoTable.render(render_each(records), fields: format.keys, resize: false)
  end

  def render_each records
    records.map { |record|
      render_record record
    }
  end

  def render_record record, format = format
    format.merge(format) do |_, expression|
      record.instance_eval expression
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
techcor-0.0.8 lib/console_formatter.rb
techcor-0.0.7 lib/console_formatter.rb
techcor-0.0.6 lib/console_formatter.rb
techcor-0.0.5 lib/console_formatter.rb
techcor-0.0.4 lib/console_formatter.rb
techcor-0.0.3 lib/console_formatter.rb
techcor-0.0.2 lib/console_formatter.rb
techcor-0.0.1 lib/console_formatter.rb