Sha256: 9f3f71614ee04eb05609f8931036bf7017dd260c7e419df20abf3acc129e8858

Contents?: true

Size: 1.12 KB

Versions: 10

Compression:

Stored size: 1.12 KB

Contents

module Terminal
  class Table
    class Row
      
      ##
      # Row cells
      
      attr_reader :cells
      
      attr_reader :table
      
      ##
      # Initialize with _width_ and _options_.
      
      def initialize table, array = []
        @cell_index = 0
        @table = table
        @cells = []
        array.each { |item| self << item }
      end
      
      def add_cell item
        options = item.is_a?(Hash) ? item : {:value => item}
        cell = Cell.new(options.merge(:index => @cell_index, :table => @table))
        @cell_index += cell.colspan
        @cells << cell
      end
      alias << add_cell
      
      def [] index
        cells[index]
      end
      
      def height
        cells.map { |c| c.lines.count }.max
      end

      def wrap_cell(index, width) 
        return if @cells.nil? or @cells[index].nil?
        @cells[index].wrap(width)
      end
      
      def render
        y = @table.style.border_y
        (0...height).to_a.map do |line|
          y + cells.map do |cell|
            cell.render(line)
          end.join(y) + y
        end.join("\n")
      end
    end
  end
end

Version data entries

10 entries across 10 versions & 2 rubygems

Version Path
galileo-0.2.0 lib/terminal-table/lib/terminal-table/row.rb
galileo-0.1.1 lib/terminal-table/lib/terminal-table/row.rb
galileo-0.1.0 lib/terminal-table/lib/terminal-table/row.rb
glom-1.0.0 lib/glom/terminal-table/row.rb
glom-0.0.6 lib/glom/terminal-table/row.rb
glom-0.0.5 lib/glom/terminal-table/row.rb
glom-0.0.4 lib/glom/terminal-table/row.rb
glom-0.0.3 lib/glom/terminal-table/row.rb
glom-0.0.2 lib/glom/terminal-table/row.rb
glom-0.0.1 lib/glom/terminal-table/row.rb