Class: Html2rss::Config

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

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of Config



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

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

Instance Method Details

#attribute_namesObject



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

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

#authorObject



9
10
11
# File 'lib/html2rss/config.rb', line 9

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

#categoriesObject



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

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

#descriptionObject



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

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

#headersObject



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

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

#languageObject



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

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

#options(name) ⇒ Object



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

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

#selector(name) ⇒ Object



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

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

#time_zoneObject



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

def time_zone
  channel_config.fetch 'time_zone', 'UTC'
end

#titleObject



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

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

#ttlObject



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

def ttl
  channel_config.fetch 'ttl', 3600
end

#urlObject Also known as: link



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

def url
  channel_config.dig 'url'
end