Sha256: 5b4c7653072a06bb34f7e695696fb90af8d9ad2b07356fdcc32799c89d3f9cae

Contents?: true

Size: 627 Bytes

Versions: 6

Compression:

Stored size: 627 Bytes

Contents

require 'terminal-table'

class Ld::Table

  def initialize models
    @models = models
  end

  def self.p models,fields
    t = Terminal::Table.new
    t.title = models.first.class.to_s
    fields = (fields.class == Array ? fields : fields.split(',')).map{|f| f.rstrip.lstrip}
    t.headings = fields
    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
      }
    }#.sort{|a,b| a[2] <=> b[2]}
        .each{|row| t.add_row row}
    puts t
  end

end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
ld-0.1.11 lib/ld/table.rb
ld-0.1.10 lib/ld/table.rb
ld-0.1.9 lib/ld/table.rb
ld-0.1.8 lib/ld/table.rb
ld-0.1.7 lib/ld/table.rb
ld-0.1.6 lib/ld/table.rb