class TransmissionRSS::Feed
Attributes
config[R]
regexp[R]
url[R]
validate_cert[R]
Public Class Methods
new(config = {})
click to toggle source
# File lib/transmission-rss/feed.rb, line 5 def initialize(config = {}) @download_paths = {} case config when Hash @config = config @url = URI.escape(config['url'] || config.keys.first) @download_path = config['download_path'] @validate_cert = config['validate_cert'].nil? || config['validate_cert'] 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 @config = {} @url = config.to_s end end
Public Instance Methods
download_path(title = nil)
click to toggle source
# File lib/transmission-rss/feed.rb, line 30 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 @download_path end
matches_regexp?(title)
click to toggle source
# File lib/transmission-rss/feed.rb, line 40 def matches_regexp?(title) @regexp.nil? || !(title =~ @regexp).nil? end
Private Instance Methods
build_regexp(matchers)
click to toggle source
# File lib/transmission-rss/feed.rb, line 46 def build_regexp(matchers) matchers = Array(matchers).map { |m| to_regexp(m) } matchers.empty? ? nil : Regexp.union(matchers) end
initialize_download_paths(regexps)
click to toggle source
# File lib/transmission-rss/feed.rb, line 51 def initialize_download_paths(regexps) return unless regexps.is_a?(Array) regexps.each do |regexp| matcher = regexp['matcher'] path = regexp['download_path'] @download_paths[matcher] = path if matcher && path end end
to_regexp(s)
click to toggle source
# File lib/transmission-rss/feed.rb, line 62 def to_regexp(s) Regexp.new(s, Regexp::IGNORECASE) end