Class: RssFeed::Feed::Base

Inherits:
Object show all
Defined in:
lib/rss_feed/feed/base.rb

Overview

The Base class serves as the base class for all feed parsers.

Direct Known Subclasses

Channel, Item

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(document) ⇒ Base

Initializes a new Base instance.

Parameters:

  • document (Nokogiri::XML::Document) —

    The parsed XML document.



10
11
12
# File 'lib/rss_feed/feed/base.rb', line 10

def initialize(document)
  @document = document
end

Instance Attribute Details

#document ⇒ Object (readonly)

Returns the value of attribute document.



5
6
7
# File 'lib/rss_feed/feed/base.rb', line 5

def document
  @document
end

Instance Method Details

#detect_feed_type ⇒ String

Detects the type of the feed based on the root element of the XML document.

Returns:

  • (String) —

    The name of the root element.



24
25
26
# File 'lib/rss_feed/feed/base.rb', line 24

def detect_feed_type
  document.root.name
end

#execute_method ⇒ Object

Executes the appropriate parsing method based on the detected feed type.

Raises:

  • (NotImplementedError) —

    If the parsing method for the detected feed type is not implemented.



31
32
33
34
35
36
# File 'lib/rss_feed/feed/base.rb', line 31

def execute_method
  method_name = detect_feed_type
  raise NotImplementedError unless respond_to?(method_name)

  send(method_name)
end

#parser ⇒ Object

This method is abstract.

This method should be implemented by subclasses to define the specific parsing logic.

Raises:

  • (NotImplementedError)


17
18
19
# File 'lib/rss_feed/feed/base.rb', line 17

def parser
  raise NotImplementedError
end