Sha256: d5cac03ef08cf537bb969e56cf602392db2e722967072414ee1ae476b2e1fd27
Contents?: true
Size: 689 Bytes
Versions: 1
Compression:
Stored size: 689 Bytes
Contents
module Mcoin # :nodoc: class Printer def initialize(*rows) @rows = rows.flatten end def print puts row(columns.map(&:capitalize)) puts column_widths.map { |width| '-' * width }.join(' | ') @rows.each do |row| puts row(columns.map { |column| row.send(column) }) end end def row(row) row.map(&:to_s) .zip(column_widths) .map { |item| item.reduce(:ljust) } .join(' | ') end def column_widths @widths ||= columns.map do |column| [@rows.map(&column).map(&:size).max, column.size].max end end def columns %i[currency type last ask bid] end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
mcoin-0.1.0 | lib/mcoin/printer.rb |