Class: Legitable::Table
- Inherits:
-
Object
- Object
- Legitable::Table
- Defined in:
- lib/legitable/table.rb
Instance Attribute Summary collapse
-
#delimiter ⇒ Object
readonly
Returns the value of attribute delimiter.
-
#format ⇒ Object
readonly
Returns the value of attribute format.
-
#headers ⇒ Object
readonly
Returns the value of attribute headers.
-
#rows ⇒ Object
readonly
Returns the value of attribute rows.
-
#separator ⇒ Object
readonly
Returns the value of attribute separator.
-
#style ⇒ Object
readonly
Returns the value of attribute style.
Instance Method Summary collapse
- #<<(data) ⇒ Object
-
#initialize(alignment: {}, delimiter: " | ", separator: "-", style: nil, &block) ⇒ Table
constructor
A new instance of Table.
- #to_s ⇒ Object
Constructor Details
#initialize(alignment: {}, delimiter: " | ", separator: "-", style: nil, &block) ⇒ Table
Returns a new instance of Table.
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/legitable/table.rb', line 7 def initialize(alignment: {}, delimiter: " | ", separator: "-", style: nil, &block) @rows = [] @headers = [] @format = {} @formatters = {} @alignment = alignment @delimiter = delimiter @separator = separator @style = style if style == :markdown @delimiter = " | " @separator = "-" end instance_eval(&block) unless block.nil? end |
Instance Attribute Details
#delimiter ⇒ Object (readonly)
Returns the value of attribute delimiter.
5 6 7 |
# File 'lib/legitable/table.rb', line 5 def delimiter @delimiter end |
#format ⇒ Object (readonly)
Returns the value of attribute format.
5 6 7 |
# File 'lib/legitable/table.rb', line 5 def format @format end |
#headers ⇒ Object (readonly)
Returns the value of attribute headers.
5 6 7 |
# File 'lib/legitable/table.rb', line 5 def headers @headers end |
#rows ⇒ Object (readonly)
Returns the value of attribute rows.
5 6 7 |
# File 'lib/legitable/table.rb', line 5 def rows @rows end |
#separator ⇒ Object (readonly)
Returns the value of attribute separator.
5 6 7 |
# File 'lib/legitable/table.rb', line 5 def separator @separator end |
#style ⇒ Object (readonly)
Returns the value of attribute style.
5 6 7 |
# File 'lib/legitable/table.rb', line 5 def style @style end |
Instance Method Details
#<<(data) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/legitable/table.rb', line 25 def <<(data) case data when Array data.each { |row| self << row } when Hash initialize_headers(data) if headers.empty? add_row data when Enumerable data.each { |row| self << row } end self end |
#to_s ⇒ Object
38 39 40 41 42 43 |
# File 'lib/legitable/table.rb', line 38 def to_s <<~EOS #{render_headers} #{render_rows} EOS end |