Sha256: d3a24e02cd31a03195be66168eca4aca2a924ae327f8cd3aebc93e6cbb51c7dc

Contents?: true

Size: 1.12 KB

Versions: 1

Compression:

Stored size: 1.12 KB

Contents

module Html2rss
  class Config
    attr_reader :feed_config, :channel_config

    def initialize(config, name)
      @config = config
      @feed_config = @config['feeds'][name.to_s]
      @channel_config = @feed_config['channel']
    end

    def author
      channel_config.fetch 'author', 'html2rss'
    end

    def ttl
      (channel_config.fetch 'ttl').to_i || nil
    end

    def title
      channel_config.fetch 'title', 'html2rss generated title'
    end

    def language
      channel_config.fetch 'language', 'en'
    end

    def description
      channel_config.fetch 'description', 'A description of my html2rss feed.'
    end

    def url
      channel_config.dig 'url'
    end
    alias link url

    def headers
      @config.fetch('headers', {})
    end

    def options(name)
      feed_config.dig('selectors', name).merge('channel' => channel_config)
    end

    def selector(name)
      feed_config.dig('selectors', name, 'selector')
    end

    def attribute_names
      attribute_names = feed_config.fetch('selectors', {}).keys.map(&:to_sym)
      attribute_names.delete(:items)
      attribute_names
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
html2rss-0.0.1 lib/html2rss/config.rb