Sha256: 86c040f347ee35a0b9afa9b94d31180ceea20b41ab57630d6266bb64dd330f82

Contents?: true

Size: 961 Bytes

Versions: 12

Compression:

Stored size: 961 Bytes

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 || 0
      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

12 entries across 12 versions & 3 rubygems

Version Path
brakeman-3.4.0 bundle/ruby/2.3.0/gems/terminal-table-1.7.1/lib/terminal-table/row.rb
terminal-table-1.7.1 lib/terminal-table/row.rb
terminal-table-1.7.0 lib/terminal-table/row.rb
brakeman-3.3.5 bundle/ruby/2.3.0/gems/terminal-table-1.6.0/lib/terminal-table/row.rb
brakeman-3.3.4 bundle/ruby/2.3.0/gems/terminal-table-1.6.0/lib/terminal-table/row.rb
brakeman-3.3.3 bundle/ruby/2.3.0/gems/terminal-table-1.6.0/lib/terminal-table/row.rb
brakeman-3.3.2 bundle/ruby/2.3.0/gems/terminal-table-1.6.0/lib/terminal-table/row.rb
terminal-table-1.6.0 lib/terminal-table/row.rb
brakeman-3.3.1 bundle/ruby/2.3.0/gems/terminal-table-1.5.2/lib/terminal-table/row.rb
brakeman-3.3.0 bundle/ruby/2.3.0/gems/terminal-table-1.5.2/lib/terminal-table/row.rb
leifcr-terminal-table-1.5.3 lib/terminal-table/row.rb
terminal-table-1.5.2 lib/terminal-table/row.rb