Sha256: 5c26a415b1aa46afdffc789cb094fc938881a48596ebab01c90f8a945c6bba0e

Contents?: true

Size: 1.21 KB

Versions: 3

Compression:

Stored size: 1.21 KB

Contents

# encoding: utf-8

require_relative 'orientation/horizontal'
require_relative 'orientation/vertical'

module TTY
  class Table
    # A class representing table orientation
    #
    # @api private
    class Orientation
      # The name for the orientation
      #
      # @api public
      attr_reader :name

      # Initialize an Orientation
      #
      # @api public
      def initialize(name)
        @name = name
      end

      # Coerce the name argument into an orientation
      #
      # @param [Symbol] name
      #
      # @api public
      def self.coerce(name)
        case name.to_s
        when /h|horiz(ontal)?/i
          Horizontal.new :horizontal
        when /v|ert(ical)?/i
          Vertical.new :vertical
        else
          fail InvalidOrientationError,
               'orientation must be one of :horizontal, :vertical'
        end
      end

      # Check if orientation is vertical
      #
      # @return [Boolean]
      #
      # @api public
      def vertical?
        name == :vertical
      end

      # Check if orientation is horizontal
      #
      # @return [Boolean]
      #
      # @api public
      def horizontal?
        name == :horizontal
      end
    end # Orientation
  end # Table
end # TTY

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
tty-table-0.10.0 lib/tty/table/orientation.rb
tty-table-0.9.0 lib/tty/table/orientation.rb
tty-table-0.8.0 lib/tty/table/orientation.rb