Class: TTY::Table::Orientation

Inherits:
Object
  • Object
show all
Defined in:
lib/tty/table/orientation.rb,
lib/tty/table/orientation/vertical.rb,
lib/tty/table/orientation/horizontal.rb

Overview

A class representing table orientation

Direct Known Subclasses

Horizontal, Vertical

Defined Under Namespace

Classes: Horizontal, Vertical

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name) ⇒ Orientation

Initialize an Orientation



17
18
19
# File 'lib/tty/table/orientation.rb', line 17

def initialize(name)
  @name = name
end

Instance Attribute Details

#nameObject (readonly)

The name for the orientation



12
13
14
# File 'lib/tty/table/orientation.rb', line 12

def name
  @name
end

Class Method Details

.coerce(name) ⇒ Object

Coerce the name argument into an orientation

Parameters:

  • name (Symbol)


26
27
28
29
30
31
32
33
34
35
36
# File 'lib/tty/table/orientation.rb', line 26

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

Instance Method Details

#horizontal?Boolean

Check if orientation is horizontal

Returns:

  • (Boolean)


52
53
54
# File 'lib/tty/table/orientation.rb', line 52

def horizontal?
  name == :horizontal
end

#vertical?Boolean

Check if orientation is vertical

Returns:

  • (Boolean)


43
44
45
# File 'lib/tty/table/orientation.rb', line 43

def vertical?
  name == :vertical
end