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

Returns a new instance of 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 <<-END
    def run_dsl(obj = nil, type = nil)
      @items = []
      @torrents = []

      case(type)
      when :filter
        @items = obj
      when :torrent
        @torrents = obj
      end
      
      #{contents}
    end
  END

  # Prime the DSL
  @primed = false
  run_dsl
  @primed = true
end

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