-
Notifications
You must be signed in to change notification settings - Fork 34
/
Rakefile
50 lines (39 loc) · 1.27 KB
/
Rakefile
1
2
3
4
5
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
43
44
45
46
47
48
49
require 'rubygems'
require 'httparty'
require 'nokogiri'
require 'set'
def mdc_url(type)
'http://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Objects/' + type
end
def document(url)
puts "Fetching #{url} ..."
Nokogiri.parse(HTTParty.get(url))
rescue
document(url)
end
MDC_URLS = %w(Array Boolean Date EvalError Error Function Math
Number Object RangeError ReferenceError RegExp
String SyntaxError TypeError URIError).
map(&method(:mdc_url))
ELEMENT_URL = 'https://developer.mozilla.org/en-US/docs/Web/API/element'
EVENT_URL = 'https://developer.mozilla.org/en-US/docs/Web/API/Event'
STYLE_URL = 'https://developer.mozilla.org/en-US/docs/Web/CSS/Reference'
class MethodSet < SortedSet
def add_method(link)
name = link.text.strip.gsub(/^.*\.([^\.]+)$/, '\1')
add(name) if name =~ /^[a-z][a-zA-Z0-9\_\$]*$/
end
def import(url, selector)
document(url).search(selector).each(&method(:add_method))
end
end
namespace :import do
task :method_chain do
methods = MethodSet.new
MDC_URLS.each { |url| methods.import(url, 'dt a') }
methods.import(ELEMENT_URL, 'td:first-child a:first-child')
methods.import(EVENT_URL, 'dt a')
methods.import(STYLE_URL, 'li a')
p methods.entries
end
end