Sha256: ebadbdfcef38b003a207a26079ef49058b5a25ab8ec9ef0742f310628dccdabb

Contents?: true

Size: 946 Bytes

Versions: 5

Compression:

Stored size: 946 Bytes

Contents

module Terminal
  class Table
    class Cell
      
      ##
      # Cell width.
      
      attr_reader :width
      
      ##
      # Cell value.
      
      attr_reader :value
      
      ##
      # Cell alignment.
      
      attr_reader :alignment
      
      ##
      # Column span.
      
      attr_reader :colspan
      
      ##
      # Initialize with _width_ and _options_.
      
      def initialize width, options = nil
        @width = width
        @value, options = options, {} unless Hash === options
        @value = options.fetch :value, value
        @alignment = options.fetch :alignment, :left
        @colspan = options.fetch :colspan, 1
      end
      
      ##
      # Render the cell.
      
      def render
        " #{value} ".align alignment, width + 2
      end
      alias :to_s :render
      
      ##
      # Cell length.
      
      def length
        value.to_s.length + 2
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
terminal-table-1.4.3 lib/terminal-table/cell.rb
terminal-table-1.4.2 lib/terminal-table/cell.rb
terminal-table-1.4.1 lib/terminal-table/cell.rb
terminal-table-1.4.0 lib/terminal-table/cell.rb
terminal-table-1.3.0 lib/terminal-table/cell.rb