Class: RenderAsMarkdown::Column

Inherits:
Object
  • Object
show all
Defined in:
lib/render-as-markdown/table.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#rowsObject

Returns the value of attribute rows.



62
63
64
# File 'lib/render-as-markdown/table.rb', line 62

def rows
  @rows
end

#titleObject

Returns the value of attribute title.



62
63
64
# File 'lib/render-as-markdown/table.rb', line 62

def title
  @title
end

#widthObject

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_lineObject



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_titleObject



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