class TablePrint::Printer
Public Class Methods
new(data, options={})
click to toggle source
# File lib/table_print.rb, line 19 def initialize(data, options={}) @data = Array(data).compact @options = options @columns = nil @start_time = Time.now end
table_print(data, options={})
click to toggle source
# File lib/table_print.rb, line 14 def self.table_print(data, options={}) p = new(data, options) p.table_print end
Public Instance Methods
message()
click to toggle source
# File lib/table_print.rb, line 52 def message return "Printed with config" if configged? Time.now - @start_time end
table_print()
click to toggle source
# File lib/table_print.rb, line 26 def table_print return "No data." if @data.empty? # it's groups all the way down # make a top-level group to hold everything we're about to do group = TablePrint::RowGroup.new # parse the config and attach it to the group columns.each do |c| group.set_column(c) end # copy data from original objects into the group group_data = (@data.first.is_a?(Hash) || @data.first.is_a?(Struct)) ? [@data] : @data group_data.each do |data| group.add_children(Fingerprinter.new.lift(columns, data)) end # munge the tree of data we created, to condense the output group.collapse! return "No data." if group.columns.empty? # turn everything into a string for output [group.header, group.horizontal_separator, group.format].join("\n") end
Private Instance Methods
columns()
click to toggle source
# File lib/table_print.rb, line 62 def columns return @columns if @columns defaults = TablePrint::Printable.default_display_methods(@data.first) c = TablePrint::ConfigResolver.new(@data.first.class, defaults, @options) @columns = c.columns end
configged?()
click to toggle source
# File lib/table_print.rb, line 58 def configged? !!Config.for(@data.first.class) end