Class: DSL
- Inherits:
-
Object
- Object
- DSL
- Defined in:
- lib/dsl.rb
Instance Attribute Summary collapse
-
#titles ⇒ Object
Returns the value of attribute titles.
Instance Method Summary collapse
- #add_feed(feed) ⇒ Object
- #add_title(title) ⇒ Object
- #after(&block) ⇒ Object
- #download(link, options = {}) ⇒ Object
- #download_complete(torrents) ⇒ Object
- #feeds ⇒ Object
- #filter(&block) ⇒ Object
-
#initialize(options) ⇒ DSL
constructor
A new instance of DSL.
- #log ⇒ Object
- #options ⇒ Object
- #parse_metadata(item) ⇒ Object
- #perform_filter(items) ⇒ Object
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 = @items, @torrents, @feeds, @titles = [], [], [], [] contents = '' [:filter_paths].each do |path| begin File.open(path, 'r') do |fh| @options[:logger].info "Adding #{path} to recipe list" if [:verbose] contents += fh.read end rescue => e @options[:logger].info "Couldn't add #{path} to recipe list: #{e}" if [: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
#titles ⇒ Object
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, = {}) Torrent.download(link, , self.) end |
#download_complete(torrents) ⇒ Object
48 49 50 |
# File 'lib/dsl.rb', line 48 def download_complete(torrents) run_dsl(torrents, :torrent) end |
#feeds ⇒ Object
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 |
#log ⇒ Object
68 69 70 |
# File 'lib/dsl.rb', line 68 def log [:logger] end |
#options ⇒ Object
72 73 74 |
# File 'lib/dsl.rb', line 72 def @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 |