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



20
21
22
# File 'lib/tty/table/orientation.rb', line 20

def initialize(name)
  @name = name
end

Instance Attribute Details

#nameObject (readonly)

The name for the orientation



15
16
17
# File 'lib/tty/table/orientation.rb', line 15

def name
  @name
end

Class Method Details

.coerce(name) ⇒ Object

Coerce the name argument into an orientation

Parameters:

  • name (Symbol)


29
30
31
32
33
34
35
36
37
38
39
# File 'lib/tty/table/orientation.rb', line 29

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
    raise InvalidOrientationError,
          "orientation must be one of :horizontal, :vertical"
  end
end

Instance Method Details

#horizontal?Boolean

Check if orientation is horizontal

Returns:

  • (Boolean)


55
56
57
# File 'lib/tty/table/orientation.rb', line 55

def horizontal?
  name == :horizontal
end

#vertical?Boolean

Check if orientation is vertical

Returns:

  • (Boolean)


46
47
48
# File 'lib/tty/table/orientation.rb', line 46

def vertical?
  name == :vertical
end