Class: RSSable::Detection::EngineDetector

Inherits:
Object
  • Object
show all
Defined in:
lib/rssable/detection/engine_detector.rb

Constant Summary collapse

MAPPINGS =
{
  blogger: /\/feeds\/posts\/default\?alt\=rss$/,
  wordpress: /\/feed\/$/,
  medium: /medium\.com\/feed\//
}

Class Method Summary collapse

Class Method Details

.call(urls:, source_url:) ⇒ Array

It returns array of RSS feed link and the driver If feed link is not found it returns blank array If the provider is not detected it returns :default

Returns:

  • (Array)


15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/rssable/detection/engine_detector.rb', line 15

def self.call(urls:, source_url:)
  result = nil

  urls.each do |url|
    result = if url.match(MAPPINGS[:blogger])
      [url, :blogger]
    elsif url.match(MAPPINGS[:wordpress]) && url.match(/\/comments\//).nil?
      [url, :wordpress]
    elsif url.match(MAPPINGS[:medium])
      [url, :medium]
    elsif url == "/feed.xml"
      parsed_url = URI.join(source_url, "/feed.xml")
      [parsed_url.to_s, :jekyll]
    end

    break unless result.nil?
  end

  return result unless result.nil?

  if urls.size != 0
    [urls.first, :default]
  else
    []
  end
end