module TablePuts
Public Class Methods
call(data, min_width: self.min_column_width, max_width: self.max_column_width)
click to toggle source
Takes in data in the form of an array of hashes all with the same keys and prints a nice looking table
# File lib/table_puts.rb, line 18 def self.call(data, min_width: self.min_column_width, max_width: self.max_column_width) Printer.new(data, min_width, max_width).call end
csv(path, min_width: self.min_column_width, max_width: self.max_column_width)
click to toggle source
Takes in the file path of a CSV and prints a nice looking table
# File lib/table_puts.rb, line 23 def self.csv(path, min_width: self.min_column_width, max_width: self.max_column_width) Printer.new(read_csv(path), min_width, max_width).call end
Private Class Methods
read_csv(path)
click to toggle source
Transforms CSV into an array of hashes
# File lib/table_puts.rb, line 30 def self.read_csv(path) csv_data = CSV.open(path).read keys = csv_data.shift csv_data.map { |items| items.map.with_index { |item, i| [keys[i], item] }.to_h } end