Sha256: 48b558c24646b2fb2899252109c668d0c3b0e6fbe841b83fe1e725a26906e5d4

Contents?: true

Size: 627 Bytes

Versions: 14

Compression:

Stored size: 627 Bytes

Contents

require 'terminal-table'

class Ld::Print

  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

14 entries across 14 versions & 1 rubygems

Version Path
ld-0.3.5 lib/ld/print/print.rb
ld-0.3.3 lib/ld/print/print.rb
ld-0.3.2 lib/ld/print/print.rb
ld-0.3.1 lib/ld/print/print.rb
ld-0.2.14 lib/ld/print/print.rb
ld-0.2.13 lib/ld/print/print.rb
ld-0.2.12 lib/ld/print/print.rb
ld-0.2.11 lib/ld/print/print.rb
ld-0.2.10 lib/ld/print/print.rb
ld-0.2.7 lib/ld/print/print.rb
ld-0.2.6 lib/ld/print/print.rb
ld-0.2.3 lib/ld/print/print.rb
ld-0.2.2 lib/ld/print/print.rb
ld-0.2.1 lib/ld/print/print.rb