Class: Terminal::Table::Style
- Inherits:
-
Object
- Object
- Terminal::Table::Style
- Defined in:
- 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 => "+", :border_top => true, :border_bottom => true, :padding_left => 1, :padding_right => 1, :margin_left => '', :width => nil, :alignment => nil, :all_separators => false }
Instance Attribute Summary collapse
-
#alignment ⇒ Object
Returns the value of attribute alignment.
-
#all_separators ⇒ Object
Returns the value of attribute all_separators.
-
#border_bottom ⇒ Object
Returns the value of attribute border_bottom.
-
#border_i ⇒ Object
Returns the value of attribute border_i.
-
#border_top ⇒ Object
Returns the value of attribute border_top.
-
#border_x ⇒ Object
Returns the value of attribute border_x.
-
#border_y ⇒ Object
Returns the value of attribute border_y.
-
#margin_left ⇒ Object
Returns the value of attribute margin_left.
-
#padding_left ⇒ Object
Returns the value of attribute padding_left.
-
#padding_right ⇒ Object
Returns the value of attribute padding_right.
-
#width ⇒ Object
Returns the value of attribute width.
Class Method Summary collapse
Instance Method Summary collapse
- #apply(options) ⇒ Object
-
#initialize(options = {}) ⇒ Style
constructor
A new instance of Style.
- #on_change(attr) ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Style
51 52 53 |
# File 'lib/terminal-table/style.rb', line 51 def initialize = {} apply self.class.defaults.merge() end |
Instance Attribute Details
#alignment ⇒ Object
Returns the value of attribute alignment.
46 47 48 |
# File 'lib/terminal-table/style.rb', line 46 def alignment @alignment end |
#all_separators ⇒ Object
Returns the value of attribute all_separators.
48 49 50 |
# File 'lib/terminal-table/style.rb', line 48 def all_separators @all_separators end |
#border_bottom ⇒ Object
Returns the value of attribute border_bottom.
38 39 40 |
# File 'lib/terminal-table/style.rb', line 38 def border_bottom @border_bottom end |
#border_i ⇒ Object
Returns the value of attribute border_i.
36 37 38 |
# File 'lib/terminal-table/style.rb', line 36 def border_i @border_i end |
#border_top ⇒ Object
Returns the value of attribute border_top.
37 38 39 |
# File 'lib/terminal-table/style.rb', line 37 def border_top @border_top end |
#border_x ⇒ Object
Returns the value of attribute border_x.
34 35 36 |
# File 'lib/terminal-table/style.rb', line 34 def border_x @border_x end |
#border_y ⇒ Object
Returns the value of attribute border_y.
35 36 37 |
# File 'lib/terminal-table/style.rb', line 35 def border_y @border_y end |
#margin_left ⇒ Object
Returns the value of attribute margin_left.
43 44 45 |
# File 'lib/terminal-table/style.rb', line 43 def margin_left @margin_left end |
#padding_left ⇒ Object
Returns the value of attribute padding_left.
40 41 42 |
# File 'lib/terminal-table/style.rb', line 40 def padding_left @padding_left end |
#padding_right ⇒ Object
Returns the value of attribute padding_right.
41 42 43 |
# File 'lib/terminal-table/style.rb', line 41 def padding_right @padding_right end |
#width ⇒ Object
Returns the value of attribute width.
45 46 47 |
# File 'lib/terminal-table/style.rb', line 45 def width @width end |
Class Method Details
.defaults ⇒ Object
60 61 62 |
# File 'lib/terminal-table/style.rb', line 60 def defaults @@defaults end |
.defaults=(options) ⇒ Object
64 65 66 |
# File 'lib/terminal-table/style.rb', line 64 def defaults= @@defaults = defaults.merge() end |
Instance Method Details
#apply(options) ⇒ Object
55 56 57 |
# File 'lib/terminal-table/style.rb', line 55 def apply .each { |m, v| __send__ "#{m}=", v } end |
#on_change(attr) ⇒ Object
69 70 71 72 73 74 75 76 |
# File 'lib/terminal-table/style.rb', line 69 def on_change attr method_name = :"#{attr}=" old_method = method method_name define_singleton_method(method_name) do |value| old_method.call value yield attr.to_sym, value end end |