Module: Html2rss

Defined in:
lib/html2rss.rb,
lib/html2rss/item.rb,
lib/html2rss/config.rb,
lib/html2rss/version.rb,
lib/html2rss/feed_builder.rb,
lib/html2rss/item_extractor.rb,
lib/html2rss/attribute_post_processors.rb,
lib/html2rss/attribute_post_processors/template.rb,
lib/html2rss/attribute_post_processors/parse_uri.rb,
lib/html2rss/attribute_post_processors/substring.rb,
lib/html2rss/attribute_post_processors/parse_time.rb,
lib/html2rss/attribute_post_processors/sanitize_html.rb

Defined Under Namespace

Modules: AttributePostProcessors, ItemExtractor Classes: Config, FeedBuilder, Item

Constant Summary collapse

VERSION =
'0.3.3'.freeze

Class Method Summary collapse

Class Method Details

.feed(config) ⇒ Object

Returns the RSS object, which is generated from the provided config.

‘config`: can be a Hash or an instance of Html2rss::Config.

Example with a Ruby Hash

Html2rss.feed(
  channel: { name: 'StackOverflow: Hot Network Questions', url: 'https://stackoverflow.com' },
  selectors: {
    items: { selector: '#hot-network-questions > ul > li' },
    title: { selector: 'a' },
    link: { selector: 'a', extractor: 'href' }
  }
)


33
34
35
36
37
38
# File 'lib/html2rss.rb', line 33

def self.feed(config)
  config = Config.new(config) unless config.is_a?(Config)

  feed = FeedBuilder.new config
  feed.rss
end

.feed_from_yaml_config(file, name) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
# File 'lib/html2rss.rb', line 7

def self.feed_from_yaml_config(file, name)
  # rubocop:disable Security/YAMLLoad
  yaml = YAML.load(File.open(file))
  # rubocop:enable Security/YAMLLoad

  feed_config = yaml['feeds'][name]
  global_config = yaml.reject { |k| k == 'feeds' }

  config = Config.new(feed_config, global_config)
  feed(config)
end