Class: Html2rss::Config

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

Defined Under Namespace

Classes: IndifferentAccessHash

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(feed_config, global_config = {}) ⇒ Config

Returns a new instance of Config.



12
13
14
15
16
# File 'lib/html2rss/config.rb', line 12

def initialize(feed_config, global_config = {})
  @global_config = IndifferentAccessHash.new global_config
  @feed_config = IndifferentAccessHash.new feed_config
  @channel_config = IndifferentAccessHash.new @feed_config.fetch('channel', {})
end

Instance Attribute Details

#channel_configObject (readonly)

Returns the value of attribute channel_config.



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

def channel_config
  @channel_config
end

#feed_configObject (readonly)

Returns the value of attribute feed_config.



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

def feed_config
  @feed_config
end

#global_configObject (readonly)

Returns the value of attribute global_config.



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

def global_config
  @global_config
end

Instance Method Details

#attribute_namesObject



59
60
61
62
63
# File 'lib/html2rss/config.rb', line 59

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

#authorObject



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

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

#categoriesObject



51
52
53
# File 'lib/html2rss/config.rb', line 51

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

#descriptionObject



34
35
36
# File 'lib/html2rss/config.rb', line 34

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

#headersObject



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

def headers
  global_config.fetch('headers', {})
end

#languageObject



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

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

#options(name) ⇒ Object



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

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

#selector(name) ⇒ Object



55
56
57
# File 'lib/html2rss/config.rb', line 55

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

#titleObject



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

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

#ttlObject



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

def ttl
  channel_config.fetch 'ttl', 3600
end

#urlObject Also known as: link



38
39
40
# File 'lib/html2rss/config.rb', line 38

def url
  channel_config.dig 'url'
end