Class: Html2rss::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/html2rss/config.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config, name) ⇒ Config

Returns a new instance of Config.



5
6
7
8
9
# File 'lib/html2rss/config.rb', line 5

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

Instance Attribute Details

#channel_configObject (readonly)

Returns the value of attribute channel_config.



3
4
5
# File 'lib/html2rss/config.rb', line 3

def channel_config
  @channel_config
end

#feed_configObject (readonly)

Returns the value of attribute feed_config.



3
4
5
# File 'lib/html2rss/config.rb', line 3

def feed_config
  @feed_config
end

Instance Method Details

#attribute_namesObject



52
53
54
55
56
# File 'lib/html2rss/config.rb', line 52

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

#authorObject



11
12
13
# File 'lib/html2rss/config.rb', line 11

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

#categoriesObject



44
45
46
# File 'lib/html2rss/config.rb', line 44

def categories
  feed_config.dig('selectors').fetch('categories', [])
end

#descriptionObject



27
28
29
# File 'lib/html2rss/config.rb', line 27

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

#headersObject



36
37
38
# File 'lib/html2rss/config.rb', line 36

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

#languageObject



23
24
25
# File 'lib/html2rss/config.rb', line 23

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

#options(name) ⇒ Object



40
41
42
# File 'lib/html2rss/config.rb', line 40

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

#selector(name) ⇒ Object



48
49
50
# File 'lib/html2rss/config.rb', line 48

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

#titleObject



19
20
21
# File 'lib/html2rss/config.rb', line 19

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

#ttlObject



15
16
17
# File 'lib/html2rss/config.rb', line 15

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

#urlObject Also known as: link



31
32
33
# File 'lib/html2rss/config.rb', line 31

def url
  channel_config.dig 'url'
end