Class: MarkdownTable::AlignRow

Inherits:
Object
  • Object
show all
Defined in:
lib/markdown_table/align_row.rb

Constant Summary collapse

ALIGNS =
{
  normal: '-',
  center: ':-:',
  left: ':-',
  right: '-:'
}.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(size:, align: []) ⇒ AlignRow

Returns a new instance of AlignRow.



14
15
16
17
# File 'lib/markdown_table/align_row.rb', line 14

def initialize(size:, align: [])
  @size = size
  @align = align
end

Instance Attribute Details

#alignObject (readonly)

Returns the value of attribute align.



5
6
7
# File 'lib/markdown_table/align_row.rb', line 5

def align
  @align
end

#sizeObject (readonly)

Returns the value of attribute size.



5
6
7
# File 'lib/markdown_table/align_row.rb', line 5

def size
  @size
end

Instance Method Details

#generateObject



19
20
21
22
23
24
25
26
27
28
29
# File 'lib/markdown_table/align_row.rb', line 19

def generate
  algin_row = Array.new(@size, ALIGNS[:normal])
  @align.each_with_index do |value, key|
    next if ALIGNS[value].nil?
    next if algin_row[key].nil?

    algin_row[key] = ALIGNS[value]
  end

  "|#{algin_row.join('|')}|\n"
end