-
Notifications
You must be signed in to change notification settings - Fork 3
/
importer.rb.old
68 lines (45 loc) · 1.46 KB
/
importer.rb.old
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
require 'rubygems'
require 'open-uri'
# require 'nokogiri'
uri = 'http://code.google.com/apis/maps/documentation/javascript/reference.html'
doc = open(uri).read()
parts = doc.split(/<h2><a name="[A-Z]\w+"><\/a>/)
first = true
parts.shift()
parts.each do |pt|
if first : first = false; next; end
str = pt
# print pt
# name, description, remainder = str.match(/^\s*([A-Z]\w+)<\/h2>.*?<p>(\w+)<\/p>(.*)/m)
# res = str.match(/^\s*([A-Z]\w+) class<\/h2>[^<]*<p>(.*?)(?=(<\/p>))(.*)/m)
res = str.match(/^\s*([A-Z]\w+).*?<\/h2>[^<]*<p>(.*?)(?=(<\/p>))(.*)/m)
# p str
class_name = res[1]
class_doc = res[2]
remains = res[4]
section_parts = remains.split(/<h3>/m)
section_name = remains.match(/<h3>(.*?)(?=(<\/h3>))/)
if section_name
if section_name[1] == 'Constructor'
res = str.match(/<td>(.*?)(?=(<\/td>))(.*?)<td>(.*?)(?=(<\/td>))/m)
code = res[1]
desc = res[4]
code.gsub!(/<[\w\/ \"\=\#]+>/,"") # extract html content
code.gsub!(/(\w+)\?/,"?\\1") # swap the question mark side
ret = ''
else
res = str.match(/<td>(.*?)(?=(<\/td>))(.*?)<td>(.*?)(?=(<\/td>))(.*?)<td>(.*?)(?=(<\/td>))/m)
p str
code = res[1]
ret = res[4]
desc = res[7]
code.gsub!(/<[\w\/ \"\=\#]+>/,"") # extract html content
code.gsub!(/(\w+)\?/,"?\\1") # swap the question mark side
end
end
end
# print str
# print str
# print section
# section.scan(/<h3>/){|w| print w}
# parts.each {|p| }