Class: MarkdownMetrics::TopElementsParser

Inherits:
Object
  • Object
show all
Defined in:
lib/markdown_metrics/top_elements_parser.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(lines) ⇒ TopElementsParser

Returns a new instance of TopElementsParser.



5
6
7
8
# File 'lib/markdown_metrics/top_elements_parser.rb', line 5

def initialize(lines)
  @lines = lines
  @elements = []
end

Instance Attribute Details

#elementsObject (readonly)

Returns the value of attribute elements.



3
4
5
# File 'lib/markdown_metrics/top_elements_parser.rb', line 3

def elements
  @elements
end

Instance Method Details

#parseObject



10
11
12
13
14
15
16
17
18
19
20
# File 'lib/markdown_metrics/top_elements_parser.rb', line 10

def parse
  @lines.each_with_index_and_catch do |line, index|
    element = initialize_element(line, index)
    @elements << {
      name: element.name,
      value: element.value
    }.merge(element.attributes)
    
    throw :skip_iteration, element.skip_lines_until if element.skip_lines_until > 0
  end
end