Class: Weneedfeed::Scraping

Inherits:
Object
  • Object
show all
Defined in:
lib/weneedfeed/scraping.rb

Constant Summary collapse

DEFAULT_HEADERS =
{
  'User-Agent' => 'Weneedfeed'
}.freeze

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(description:, item_description_selector:, item_image_selector:, item_link_selector:, item_time_selector:, item_title_selector:, item_selector:, title:, url:) ⇒ Scraping

Returns a new instance of Scraping.

Parameters:

  • description (String, nil)
  • item_description_selector (String, nil)
  • item_image_selector (String, nil)
  • item_link_selector (String)
  • item_time_selector (String, nil)
  • item_title_selector (String)
  • item_selector (String)
  • title (String)
  • url (String)


30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/weneedfeed/scraping.rb', line 30

def initialize(
  description:,
  item_description_selector:,
  item_image_selector:,
  item_link_selector:,
  item_time_selector:,
  item_title_selector:,
  item_selector:,
  title:,
  url:
)
  @description = description
  @item_description_selector = item_description_selector
  @item_image_selector = item_image_selector
  @item_link_selector = item_link_selector
  @item_time_selector = item_time_selector
  @item_title_selector = item_title_selector
  @item_selector = item_selector
  @title = title
  @url = url
end

Class Method Details

.faraday_connectionFaraday::Connection

Returns:

  • (Faraday::Connection)


14
15
16
17
18
# File 'lib/weneedfeed/scraping.rb', line 14

def faraday_connection
  @faraday_connection ||= ::Faraday.new(headers: DEFAULT_HEADERS) do |connection|
    connection.use ::Weneedfeed::FaradayResponseMiddleware
  end
end

Instance Method Details

#callWeneedfeed::Page

Returns:



53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/weneedfeed/scraping.rb', line 53

def call
  ::Weneedfeed::Page.new(
    description: @description,
    node: parsed_body,
    item_description_selector: @item_description_selector,
    item_image_selector: @item_image_selector,
    item_selector: @item_selector,
    item_link_selector: @item_link_selector,
    item_time_selector: @item_time_selector,
    item_title_selector: @item_title_selector,
    title: @title,
    url: @url
  )
end