Sha256: da4942dc749bf0464dbf2489033ce5a530b6e30b0e1aef2a464dbc6b5b6dbd55
Contents?: true
Size: 1.02 KB
Versions: 1
Compression:
Stored size: 1.02 KB
Contents
require 'terminal-table' class Ld::Print def self.p models, fields self.print "#{models.first.class.to_s}" do |table| table.set_headings (fields.class == Array ? fields : fields.split(',')).map{|f| f.rstrip.lstrip} table.set_rows models.map { |model| fields.map { |field| value = model.send field value = value.strftime("%Y/%m/%d %H:%M:%S") if [Date, Time, DateTime, ActiveSupport::TimeWithZone].include? value.class value } } end end def self.print hash t = Terminal::Table.new t.title = hash[:title] t.headings = hash[:headings] t.rows = hash[:rows] puts t end def self.ls dir t = Terminal::Table.new t.title = "目录列表:#{dir.path}" t.headings = ["name","type","size","permission"] t.rows = dir.children.map{|f| [f.name, f.type, f.size, f.mode] if f.name[0] != '.'}.compact.sort{|a,b| a[1] <=> b[1]} puts t end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
ld-0.3.6 | lib/ld/print/print.rb |