Class: DSL

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ DSL



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/dsl.rb', line 6

def initialize(options)
  @options = options
  @items, @torrents, @feeds, @titles = [], [], [], []
  
  contents = ''
  options[:filter_paths].each do |path|
    begin
      File.open(path, 'r') do |fh|
        @options[:logger].info "Adding #{path} to recipe list" if options[:verbose]
        contents += fh.read
      end
    rescue => e
      @options[:logger].info "Couldn't add #{path} to recipe list: #{e}" if options[:verbose]
    end
  end

  eval "    def run_dsl(obj = nil, type = nil)\n      @items = []\n      @torrents = []\n\n      case(type)\n      when :filter\n        @items = obj\n      when :torrent\n        @torrents = obj\n      end\n      \n      \#{contents}\n    end\n  END\n\n  # Prime the DSL\n  @primed = false\n  run_dsl\n  @primed = true\nend\n"

Instance Attribute Details

#titlesObject

Returns the value of attribute titles.



4
5
6
# File 'lib/dsl.rb', line 4

def titles
  @titles
end

Instance Method Details

#add_feed(feed) ⇒ Object



52
53
54
# File 'lib/dsl.rb', line 52

def add_feed(feed)
  @feeds << feed unless @primed
end

#add_title(title) ⇒ Object



60
61
62
# File 'lib/dsl.rb', line 60

def add_title(title)
  @titles << title unless @primed
end

#after(&block) ⇒ Object



84
85
86
# File 'lib/dsl.rb', line 84

def after &block
  @torrents.each { |torrent| yield(torrent) }
end

#download(link, options = {}) ⇒ Object



76
77
78
# File 'lib/dsl.rb', line 76

def download(link, options = {})
  Torrent.download(link, options, self.options) 
end

#download_complete(torrents) ⇒ Object



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

def download_complete(torrents)
  run_dsl(torrents, :torrent)
end

#feedsObject



56
57
58
# File 'lib/dsl.rb', line 56

def feeds
  @feeds
end

#filter(&block) ⇒ Object



80
81
82
# File 'lib/dsl.rb', line 80

def filter &block
  @items.each { |item| yield(item) }
end

#logObject



68
69
70
# File 'lib/dsl.rb', line 68

def log
  options[:logger]
end

#optionsObject



72
73
74
# File 'lib/dsl.rb', line 72

def options
  @options
end

#parse_metadata(item) ⇒ Object



64
65
66
# File 'lib/dsl.rb', line 64

def (item)
  Lexicon.parse(item) 
end

#perform_filter(items) ⇒ Object



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

def perform_filter(items)
  run_dsl(items, :filter)
end