/usr/lib/ruby/vendor_ruby/table_print.rb is in ruby-table-print 1.5.6-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 | require 'table_print/column'
require 'table_print/config_resolver'
require 'table_print/config'
require 'table_print/fingerprinter'
require 'table_print/formatter'
require 'table_print/hash_extensions'
require 'table_print/printable'
require 'table_print/row_group'
require 'table_print/returnable'
module TablePrint
class Printer
def self.table_print(data, options={})
p = new(data, options)
p.table_print
end
def initialize(data, options={})
@data = Array(data).compact
@options = options
@columns = nil
@start_time = Time.now
end
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
def message
return "Printed with config" if configged?
Time.now - @start_time
end
private
def configged?
!!Config.for(@data.first.class)
end
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
end
end
def tp(data=Class, *options)
printer = TablePrint::Printer.new(data, options)
TablePrint::Config.io.puts printer.table_print unless data.is_a? Class
TablePrint::Returnable.new(printer.message) # we have to return *something*, might as well be execution time.
end
|