Class: LighterpackParser::Parser

Inherits:
Object
  • Object
show all
Defined in:
lib/lighterpack_parser/parser.rb

Overview

Main parser for extracting data from Lighterpack list HTML pages.

Orchestrates the parsing process by coordinating ListParser, CategoryParser, and ItemParser to extract structured data from Lighterpack HTML.

Instance Method Summary collapse

Constructor Details

#initialize(html: nil, url: nil) ⇒ Parser

Returns a new instance of Parser.



12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/lighterpack_parser/parser.rb', line 12

def initialize(html: nil, url: nil)
  @html = if url
            fetch_html(url)
          elsif html
            html
          else
            raise ArgumentError, 'Either html or url must be provided'
          end
  @item_parser = ItemParser.new
  @category_parser = CategoryParser.new
  @list_parser = ListParser.new
end

Instance Method Details

#parseObject



25
26
27
28
# File 'lib/lighterpack_parser/parser.rb', line 25

def parse
  doc = Nokogiri::HTML(@html)
  @list_parser.parse(doc, category_parser: @category_parser, item_parser: @item_parser)
end