Class: Pennyworth::Loaders::HTMX

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

Overview

Loads htmx documentation by scraping web page.

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(model: Models::HTMX) ⇒ HTMX

Returns a new instance of HTMX.



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

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

Class Method Details

.text_for(element) ⇒ Object



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

def self.text_for element
  parts = element.each.with_object [] do |item, content|
    text = if item.is_a? Ox::Element
             "`#{item.text}`"
           else
             item.encode ::Encoding::UTF_8, replace: Core::EMPTY_STRING
           end

    content.append text
  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