Class: Pennyworth::Loaders::HTMX

Inherits:
Object
  • Object
show all
Defined in:
lib/pennyworth/loaders/htmx.rb

Overview

Loads htmx records by scraping web page.

Instance Method Summary collapse

Constructor Details

#initialize(parser: Nokogiri::HTML5, model: Models::HTMX) ⇒ HTMX

Returns a new instance of HTMX.



12
13
14
15
16
# File 'lib/pennyworth/loaders/htmx.rb', line 12

def initialize(parser: Nokogiri::HTML5, model: Models::HTMX, **)
  @parser = parser
  @model = model
  super(**)
end

Instance Method Details

#call(uri) ⇒ Object



18
19
20
21
22
23
24
25
# File 'lib/pennyworth/loaders/htmx.rb', line 18

def call uri
  fetch(uri).then { parse_rows it }
            .each
            .with_object [] do |row, entries|
    row.children in Nokogiri::XML::Element => item, Nokogiri::XML::Element => description
    entries.append build_record(item, description) unless item.text.include? "Soon"
  end
end