Sha256: 7e795f00218a92e45b660acce44fa81527045e883c500f8d04ffec2f5a5a4e21

Contents?: true

Size: 1.52 KB

Versions: 3

Compression:

Stored size: 1.52 KB

Contents

require 'hirb'
require 'hirb-unicode'

module PTT

  class DataTable

    extend ::Hirb::Console

    def initialize(dataset)
      @rows = dataset.map{ |row| DataRow.new(row, dataset) }
    end

    def print(config={})
      if @rows.empty?
        puts "\n#{'-- empty list --'.center(36)}\n"
      else

        max_width = Hirb::Util.detect_terminal_size()[0]
        if config[:max_width] && config[:max_width] < max_width
          max_width = config[:max_width]
        end

        self.class.table @rows, :fields => [:num] + self.class.fields,
             :change_fields => %w{num pt_id},
             :unicode => true, :description => false,
             :max_width => max_width
      end
    end

    def [](pos)
      pos = pos.to_i
      (pos < 1 || pos > @rows.length) ? nil : @rows[pos-1].record
    end

    def length
      @rows.length
    end

    def self.fields
      []
    end

  end


  class ProjectTable < DataTable

    def self.fields
      [:name]
    end

  end


  class TasksTable < DataTable

    def self.fields
      [:name, :state, :id]
    end

  end

  class MultiUserTasksTable < DataTable

    def self.fields
      [:owned_by, :name, :state, :id]
    end

  end

  class PersonsTable < DataTable

    def self.fields
      [:name]
    end

  end

  class MembersTable < DataTable

    def self.fields
      [:name]
    end

  end

  class TodoTaskTable < DataTable

    def self.fields
      [:description]
    end
  end

  class ActionTable < DataTable

    def self.fields
      [:action]
    end
  end

end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
ptt-1.0.3 lib/ptt/data_table.rb
ptt-1.0.2 lib/ptt/data_table.rb
ptt-1.0.1 lib/ptt/data_table.rb