Class: MarkdownMetrics::Elements::Block::Table

Inherits:
MarkdownMetrics::Elements::Base show all
Defined in:
lib/markdown_metrics/elements/block/table.rb

Instance Attribute Summary

Attributes inherited from MarkdownMetrics::Elements::Base

#skip_lines_until

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from MarkdownMetrics::Elements::Base

#attributes, #initialize

Constructor Details

This class inherits a constructor from MarkdownMetrics::Elements::Base

Class Method Details

.match_element(line, next_line) ⇒ Object



7
8
9
# File 'lib/markdown_metrics/elements/block/table.rb', line 7

def self.match_element(line, next_line)
  line.to_s.match(/^.* \| .*$/) && next_line.to_s.match(/^\-{1,} \| \-{1,}$/)
end

Instance Method Details

#nameObject



11
12
13
# File 'lib/markdown_metrics/elements/block/table.rb', line 11

def name
  :table
end

#valueObject



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/markdown_metrics/elements/block/table.rb', line 15

def value
  headers = current_line.split("|")
  rows = []
  end_line = nil
  next_line = @start_at

  @lines[(@start_at + 2)..-1].each do |code_line|
    next_line += 1
    unless code_line.match(/^.* \| .*$/)
      end_line = next_line
      break
    end

    end_line = @lines.size - 1 if end_line.nil?
  end

  if !end_line.nil?
    @skip_lines_until = end_line
    @lines[@start_at+2..end_line].each do |row_line|
      rows << row_line.split("|")
    end

    { rows: rows, headers: headers }
  end
end