Class: Pennyworth::Loaders::HTMX

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

Overview

Loads htmx documentation by scraping web page.

Constant Summary collapse

PARSER =
Ox.tap do |ox|
  ox.default_options = {mode: :generic, effort: :tolerant, smart: true}
end

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(parser: PARSER, model: Models::HTMX) ⇒ HTMX

Returns a new instance of HTMX.



27
28
29
30
31
# File 'lib/pennyworth/loaders/htmx.rb', line 27

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

Class Method Details

.text_for(element) ⇒ Object



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

def self.text_for element
  parts = element.each.with_object [] do |item, content|
    content.append item.is_a?(Ox::Element) ? "`#{item.text}`" : item
  end

  parts.join.up.delete_suffix "."
end

Instance Method Details

#call(uri) ⇒ Object



33
34
35
36
37
38
39
# File 'lib/pennyworth/loaders/htmx.rb', line 33

def call uri
  read(uri).each.with_object [] do |row, entries|
    next unless row.locate("td") in Ox::Element => item, Ox::Element => description

    entries.append record_for(item, description, uri)
  end
end