Class: TransmissionRSS::Feed

Inherits:
Object
  • Object
show all
Defined in:
lib/transmission-rss/feed.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config = {}) ⇒ Feed

Returns a new instance of Feed.



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/transmission-rss/feed.rb', line 5

def initialize(config = {})
  @download_paths = {}

  case config
  when Hash
    @url = URI.encode(config['url'] || config.keys.first)

    @download_path = config['download_path']

    matchers = Array(config['regexp']).map do |e|
      e.is_a?(String) ? e : e['matcher']
    end

    @regexp = build_regexp(matchers)

    initialize_download_paths(config['regexp'])
  else
    @url = config.to_s
  end
end

Instance Attribute Details

#regexpObject (readonly)

Returns the value of attribute regexp.



3
4
5
# File 'lib/transmission-rss/feed.rb', line 3

def regexp
  @regexp
end

#urlObject (readonly)

Returns the value of attribute url.



3
4
5
# File 'lib/transmission-rss/feed.rb', line 3

def url
  @url
end

Instance Method Details

#download_path(title = nil) ⇒ Object



26
27
28
29
30
31
32
33
34
# File 'lib/transmission-rss/feed.rb', line 26

def download_path(title = nil)
  return @download_path if title.nil?

  @download_paths.each do |regexp, path|
    return path if title =~ to_regexp(regexp)
  end

  return @download_path
end

#matches_regexp?(title) ⇒ Boolean

Returns:

  • (Boolean)


36
37
38
# File 'lib/transmission-rss/feed.rb', line 36

def matches_regexp?(title)
  @regexp.nil? || !(title =~ @regexp).nil?
end