Class: Ld::Print
- Inherits:
-
Object
- Object
- Ld::Print
- Defined in:
- lib/ld/print/print.rb
Class Method Summary collapse
Class Method Details
.ls(dir) ⇒ Object
26 27 28 29 30 31 32 |
# File 'lib/ld/print/print.rb', line 26 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 |
.p(models, fields) ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 |
# File 'lib/ld/print/print.rb', line 5 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 |
.print(hash) ⇒ Object
18 19 20 21 22 23 24 |
# File 'lib/ld/print/print.rb', line 18 def self.print hash t = Terminal::Table.new t.title = hash[:title] t.headings = hash[:headings] t.rows = hash[:rows] puts t end |