Skip to content

Instantly share code, notes, and snippets.

@manveru
Created October 4, 2010 00:53
Show Gist options
  • Select an option

  • Save manveru/609100 to your computer and use it in GitHub Desktop.

Select an option

Save manveru/609100 to your computer and use it in GitHub Desktop.
module NaquaDSL
class << self
options = {
:pages => 2,
:cookie_file => './cookies.txt'
}
feeds = {}
define_method :set do |*args|
args = args.flatten
options.merge!(args.shift) while args.first.is_a?(Hash)
options.merge!(Hash[*args]) unless args.empty?
end
define_method :get do |k|
options[k]
end
define_method :feed do |name, *urls|
raise ArgumentError, "Feed #{name} already exists" if feeds.key?(name)
opts = options.merge(urls.first.is_a?(Hash) ? urls.shift :
urls.last.is_a?(Hash) ? urls.pop : {})
feeds[name] = {
:options => options.merge(opts),
:urls => urls.flatten
}
end
define_method :feeds do
feeds
end
end
eval(<<-TEST)
set :login => 'asdasd',
:password => '123123123',
:pages => 3
feed :series,
'http://rutracker.org/forum/tracker.php?prev_my=0&prev_new=0&prev_oop=0&f%5B%5D=189&o=1&s=2&tm=-1&pn=&nm=',
:pages => 5
TEST
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment