Class: Terminal::Table::Style

Inherits:
Object
  • Object
show all
Defined in:
lib/terminal-table-1.4.4/lib/terminal-table/style.rb

Overview

A Style object holds all the formatting information for a Table object

To create a table with a certain style, use either the constructor option :style, the Table#style object or the Table#style= method

All these examples have the same effect:

# by constructor
@table = Table.new(:style => {:padding_left => 2, :width => 40})

# by object
@table.style.padding_left = 2
@table.style.width = 40

# by method
@table.style = {:padding_left => 2, :width => 40}

To set a default style for all tables created afterwards use Style.defaults=

Terminal::Table::Style.defaults = {:width => 80}

Constant Summary collapse

@@defaults =
{
  :border_x => "-", :border_y => "|", :border_i => "+",
  :padding_left => 1, :padding_right => 1,
  :width => nil
}

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Style

Returns a new instance of Style.



42
43
44
# File 'lib/terminal-table-1.4.4/lib/terminal-table/style.rb', line 42

def initialize options = {}
  apply self.class.defaults.merge(options)
end

Instance Attribute Details

#border_iObject

Returns the value of attribute border_i.



34
35
36
# File 'lib/terminal-table-1.4.4/lib/terminal-table/style.rb', line 34

def border_i
  @border_i
end

#border_xObject

Returns the value of attribute border_x.



32
33
34
# File 'lib/terminal-table-1.4.4/lib/terminal-table/style.rb', line 32

def border_x
  @border_x
end

#border_yObject

Returns the value of attribute border_y.



33
34
35
# File 'lib/terminal-table-1.4.4/lib/terminal-table/style.rb', line 33

def border_y
  @border_y
end

#padding_leftObject

Returns the value of attribute padding_left.



36
37
38
# File 'lib/terminal-table-1.4.4/lib/terminal-table/style.rb', line 36

def padding_left
  @padding_left
end

#padding_rightObject

Returns the value of attribute padding_right.



37
38
39
# File 'lib/terminal-table-1.4.4/lib/terminal-table/style.rb', line 37

def padding_right
  @padding_right
end

#widthObject

Returns the value of attribute width.



39
40
41
# File 'lib/terminal-table-1.4.4/lib/terminal-table/style.rb', line 39

def width
  @width
end

Class Method Details

.defaultsObject



51
52
53
# File 'lib/terminal-table-1.4.4/lib/terminal-table/style.rb', line 51

def defaults
  @@defaults
end

.defaults=(options) ⇒ Object



55
56
57
# File 'lib/terminal-table-1.4.4/lib/terminal-table/style.rb', line 55

def defaults= options
  @@defaults = defaults.merge(options)
end

Instance Method Details

#apply(options) ⇒ Object



46
47
48
# File 'lib/terminal-table-1.4.4/lib/terminal-table/style.rb', line 46

def apply options
  options.each { |m, v| __send__ "#{m}=", v }
end