Class: RenderAsMarkdown::Column
- Inherits:
-
Object
- Object
- RenderAsMarkdown::Column
- Defined in:
- lib/render-as-markdown/table.rb
Instance Attribute Summary collapse
-
#rows ⇒ Object
Returns the value of attribute rows.
-
#title ⇒ Object
Returns the value of attribute title.
-
#width ⇒ Object
Returns the value of attribute width.
Instance Method Summary collapse
- #add_row(string) ⇒ Object
-
#initialize(title) ⇒ Column
constructor
A new instance of Column.
- #render_line ⇒ Object
- #render_row(row_number) ⇒ Object
- #render_title ⇒ Object
- #update_width(length) ⇒ Object
Constructor Details
#initialize(title) ⇒ Column
Returns a new instance of Column.
64 65 66 67 68 |
# File 'lib/render-as-markdown/table.rb', line 64 def initialize title @rows = [] @title = title.to_s @width = [@title.length, 1].max end |
Instance Attribute Details
#rows ⇒ Object
Returns the value of attribute rows.
62 63 64 |
# File 'lib/render-as-markdown/table.rb', line 62 def rows @rows end |
#title ⇒ Object
Returns the value of attribute title.
62 63 64 |
# File 'lib/render-as-markdown/table.rb', line 62 def title @title end |
#width ⇒ Object
Returns the value of attribute width.
62 63 64 |
# File 'lib/render-as-markdown/table.rb', line 62 def width @width end |
Instance Method Details
#add_row(string) ⇒ Object
82 83 84 85 86 |
# File 'lib/render-as-markdown/table.rb', line 82 def add_row string string ||= '' @rows << string update_width string.to_s.length end |
#render_line ⇒ Object
74 75 76 |
# File 'lib/render-as-markdown/table.rb', line 74 def render_line '-'.ljust @width, '-' end |
#render_row(row_number) ⇒ Object
78 79 80 |
# File 'lib/render-as-markdown/table.rb', line 78 def render_row row_number @rows[row_number].ljust @width end |
#render_title ⇒ Object
70 71 72 |
# File 'lib/render-as-markdown/table.rb', line 70 def render_title @title.ljust @width end |
#update_width(length) ⇒ Object
88 89 90 |
# File 'lib/render-as-markdown/table.rb', line 88 def update_width length @width = length if @width < length end |