ruby_doc 1.1.5 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.gitignore +1 -1
- data/Gemfile.lock +2 -2
- data/README.md +20 -10
- data/Rakefile +6 -0
- data/bin/ruby_doc +1 -1
- data/changelog.md +11 -1
- data/config/environment.rb +15 -9
- data/config/patches.rb +15 -0
- data/lib/ruby_doc/cli/cli.rb +16 -0
- data/lib/ruby_doc/cli/ui.rb +387 -0
- data/lib/ruby_doc/data/class.rb +18 -0
- data/lib/ruby_doc/data/data_processor.rb +35 -0
- data/lib/ruby_doc/data/method.rb +20 -0
- data/lib/ruby_doc/data/scraper.rb +139 -0
- data/lib/ruby_doc/version.rb +1 -1
- data/ruby_doc.gemspec +2 -2
- metadata +12 -13
- data/Notes.md +0 -37
- data/lib/ruby_doc/data/data_extras.rb +0 -151
- data/lib/ruby_doc/data/doc.rb +0 -16
- data/lib/ruby_doc/data/meth.rb +0 -18
- data/lib/ruby_doc/data/scrapers.rb +0 -81
- data/lib/ruby_doc/ui/CLI.rb +0 -20
- data/lib/ruby_doc/ui/UI.rb +0 -39
- data/lib/ruby_doc/ui/ui_extras.rb +0 -257
data/lib/ruby_doc/data/doc.rb
DELETED
@@ -1,16 +0,0 @@
|
|
1
|
-
class Doc
|
2
|
-
#========================modules===========================
|
3
|
-
extend DataExtras #sets/gets @@all
|
4
|
-
#inheriting: paginate, display(doc), listMeths(doc)
|
5
|
-
#=======================properties=========================
|
6
|
-
attr_accessor :name, :url, :description, :type, :methods
|
7
|
-
#==========================================================
|
8
|
-
#DocCount = 2403
|
9
|
-
def initialize(name, url)
|
10
|
-
self.name = name
|
11
|
-
self.url = url
|
12
|
-
@@all << self
|
13
|
-
self.methods = []
|
14
|
-
end
|
15
|
-
#==========================================================
|
16
|
-
end
|
data/lib/ruby_doc/data/meth.rb
DELETED
@@ -1,18 +0,0 @@
|
|
1
|
-
class Meth
|
2
|
-
#========================modules===========================
|
3
|
-
extend DataExtras #sets/gets @@all
|
4
|
-
#=================properties===================
|
5
|
-
attr_accessor :name, :url, :description, :type, :docs
|
6
|
-
#==============================================
|
7
|
-
def initialize(name, url)
|
8
|
-
self.name = name
|
9
|
-
self.url = url
|
10
|
-
@@all << self
|
11
|
-
self.docs = []
|
12
|
-
end
|
13
|
-
#==============================================
|
14
|
-
def self.find(name)
|
15
|
-
self.all.find{|meth| meth.name.downcase == name.downcase}
|
16
|
-
end
|
17
|
-
#==============================================
|
18
|
-
end
|
@@ -1,81 +0,0 @@
|
|
1
|
-
class Scraper
|
2
|
-
extend UIExtras
|
3
|
-
#inheriting: loading_message, loading_animation
|
4
|
-
|
5
|
-
#See "HELPERS"(line62) for additional methods
|
6
|
-
#==================Load Docs===================
|
7
|
-
def self.loadDOCS
|
8
|
-
@counter = 0 #For Loading anim
|
9
|
-
loading_message#
|
10
|
-
|
11
|
-
html = Nokogiri::HTML(open("https://apidock.com/ruby/browse"))
|
12
|
-
container = html.search(".hover_list")
|
13
|
-
|
14
|
-
container.search("a").each do |doc|
|
15
|
-
name = doc.text
|
16
|
-
url = prefix + doc.attribute("href").value
|
17
|
-
|
18
|
-
# assigns - Doc :names, :urls
|
19
|
-
Doc.new(name, url) if docUniq(name)
|
20
|
-
|
21
|
-
@counter += 1 #For Loading anim
|
22
|
-
loading_animation#
|
23
|
-
end
|
24
|
-
end
|
25
|
-
#===================DocPage====================
|
26
|
-
def self.loadDocPage(doc)
|
27
|
-
#Scrape1
|
28
|
-
doc_page = Nokogiri::HTML(open(doc.url))
|
29
|
-
#prerequisites
|
30
|
-
doc_page.search(".description p")[0..1].search("em").remove
|
31
|
-
container = doc_page.search("#related")
|
32
|
-
container.search("li").search(".related_header").remove
|
33
|
-
|
34
|
-
# assigns - Doc :description, :type
|
35
|
-
doc.description = parse(doc_page.search(".description p")[0..1].text)
|
36
|
-
doc.type = doc_page.search(".title_prefix span").text
|
37
|
-
#==========================================
|
38
|
-
#Scrape2
|
39
|
-
container.search("li").map do |m|
|
40
|
-
name = m.search("a").text
|
41
|
-
url = prefix + m.search("a").attribute("href").value
|
42
|
-
|
43
|
-
# assigns - Meth :name, :url >> Doc :methods
|
44
|
-
method = Meth.new(name, url) if methUniq(name)
|
45
|
-
doc.methods << name if methsUniq(doc.methods, name)
|
46
|
-
end
|
47
|
-
doc #doc instance
|
48
|
-
end
|
49
|
-
#==================MethPage====================
|
50
|
-
def self.loadMethPage(meth)
|
51
|
-
url = Nokogiri::HTML(open(meth.url))
|
52
|
-
url.search(".description p")[0..1].search("em").remove
|
53
|
-
|
54
|
-
# assigns - Meth :description, :type
|
55
|
-
meth.description = parse(url.search(".description p")[0..1].text)
|
56
|
-
meth.type = url.search(".title_prefix span").text
|
57
|
-
end
|
58
|
-
#==============================================
|
59
|
-
#HELPERS
|
60
|
-
#==============================================
|
61
|
-
def self.parse(des)
|
62
|
-
des.gsub(/[\n]/, ' ').gsub(' ',' ')
|
63
|
-
end
|
64
|
-
|
65
|
-
def self.docUniq(name)
|
66
|
-
Doc.all.none?{|doc| doc.name == name}
|
67
|
-
end
|
68
|
-
|
69
|
-
def self.methUniq(name)
|
70
|
-
Meth.all.none?{|meth| meth.name == name}
|
71
|
-
end
|
72
|
-
|
73
|
-
def self.methsUniq(col,name)
|
74
|
-
col.none?{|meth| meth == name}
|
75
|
-
end
|
76
|
-
|
77
|
-
def self.prefix
|
78
|
-
"https://apidock.com"
|
79
|
-
end
|
80
|
-
#==============================================
|
81
|
-
end
|
data/lib/ruby_doc/ui/CLI.rb
DELETED
@@ -1,20 +0,0 @@
|
|
1
|
-
module RubyDoc
|
2
|
-
#==============================================
|
3
|
-
module CLI
|
4
|
-
#===============Load Init Data================#
|
5
|
-
def self.iLoad
|
6
|
-
puts "\nThanks For Using ALPHA™ Ruby Docs!".cyan
|
7
|
-
puts "One Moment Please As We Set Things Up\n".cyan
|
8
|
-
Scraper.loadDOCS
|
9
|
-
start
|
10
|
-
end
|
11
|
-
#==============================================
|
12
|
-
def self.start
|
13
|
-
UI.signature#
|
14
|
-
UI.greeting
|
15
|
-
end
|
16
|
-
#==============================================
|
17
|
-
end
|
18
|
-
#==============================================
|
19
|
-
end
|
20
|
-
|
data/lib/ruby_doc/ui/UI.rb
DELETED
@@ -1,39 +0,0 @@
|
|
1
|
-
#==================requires====================
|
2
|
-
require_relative './ui_extras'
|
3
|
-
require_relative '../data/data_extras.rb'
|
4
|
-
#==============================================
|
5
|
-
module RubyDoc::CLI
|
6
|
-
#==================modules=====================
|
7
|
-
class UI
|
8
|
-
extend UIExtras#
|
9
|
-
#inheriting: mainMenu, mainControl, signature
|
10
|
-
extend DataExtras
|
11
|
-
#inheriting: paginateALL, superSEARCH(),
|
12
|
-
#displayMeth(), display()
|
13
|
-
#==============================================
|
14
|
-
def self.greeting
|
15
|
-
mainMenu#
|
16
|
-
mainControl# =>
|
17
|
-
end
|
18
|
-
|
19
|
-
def self.main_Shuttle(iN)
|
20
|
-
case iN
|
21
|
-
when "b"
|
22
|
-
paginateALL
|
23
|
-
when "exit!"
|
24
|
-
exit!
|
25
|
-
else
|
26
|
-
superSEARCH(iN)
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
def self.search_Shuttle(iN, matches)
|
31
|
-
iN == "m" ? greeting : display(matches[iN.to_i-1])
|
32
|
-
end
|
33
|
-
|
34
|
-
def self.meth_Shuttle(iN, doc)
|
35
|
-
displayMeth(doc.methods[iN.to_i-1])
|
36
|
-
end
|
37
|
-
#==============================================
|
38
|
-
end
|
39
|
-
end
|
@@ -1,257 +0,0 @@
|
|
1
|
-
module UIExtras
|
2
|
-
attr_reader :counter #For Loading Anim
|
3
|
-
#==============================================
|
4
|
-
#IMPORTANT!
|
5
|
-
#==================Shuttle=====================
|
6
|
-
def main
|
7
|
-
RubyDoc::CLI.start
|
8
|
-
end
|
9
|
-
#==================Control=====================
|
10
|
-
def mainControl
|
11
|
-
prompt
|
12
|
-
iN = alphaGets
|
13
|
-
iN.split.size > 1 ? mainError : RubyDoc::CLI::UI.main_Shuttle(iN)
|
14
|
-
end
|
15
|
-
|
16
|
-
def browseControl(currentPg, docRange)
|
17
|
-
prompt
|
18
|
-
iN = alphaGets
|
19
|
-
|
20
|
-
case iN
|
21
|
-
when "n"
|
22
|
-
DataExtras.nextPage(currentPg)
|
23
|
-
when "m"
|
24
|
-
main
|
25
|
-
when "exit!"
|
26
|
-
exit!
|
27
|
-
end
|
28
|
-
# else
|
29
|
-
!iN.to_i.between?(1,docRange.count) ? browseError(iN, currentPg, docRange) : Doc.display(docRange[iN.to_i-1])
|
30
|
-
end
|
31
|
-
|
32
|
-
def searchControl(matches)
|
33
|
-
matches == [] ? searchError : matches.each_with_index{|doc, index| outputD(doc, index)}
|
34
|
-
end
|
35
|
-
|
36
|
-
def choiceControl(matches)
|
37
|
-
prompt
|
38
|
-
iN = alphaGets
|
39
|
-
|
40
|
-
if iN == "m"
|
41
|
-
main
|
42
|
-
elsif iN == "exit!"
|
43
|
-
exit!
|
44
|
-
elsif !iN.to_i.between?(1,matches.count)
|
45
|
-
choiceError(matches)
|
46
|
-
else
|
47
|
-
RubyDoc::CLI::UI.search_Shuttle(iN, matches)
|
48
|
-
end
|
49
|
-
end
|
50
|
-
|
51
|
-
def docControl(doc)
|
52
|
-
prompt
|
53
|
-
iN = alphaGets
|
54
|
-
|
55
|
-
case iN
|
56
|
-
when "1"
|
57
|
-
Doc.listMeths(doc)
|
58
|
-
when "m"
|
59
|
-
main
|
60
|
-
when "exit!"
|
61
|
-
exit!
|
62
|
-
else
|
63
|
-
docError(doc)
|
64
|
-
end
|
65
|
-
end
|
66
|
-
|
67
|
-
def methControl
|
68
|
-
prompt
|
69
|
-
iN = alphaGets
|
70
|
-
|
71
|
-
case iN
|
72
|
-
when "m"
|
73
|
-
main
|
74
|
-
when "exit!"
|
75
|
-
exit!
|
76
|
-
else
|
77
|
-
methError
|
78
|
-
end
|
79
|
-
end
|
80
|
-
|
81
|
-
def methListControl(doc)
|
82
|
-
prompt
|
83
|
-
iN = alphaGets
|
84
|
-
|
85
|
-
if iN == "m"
|
86
|
-
main
|
87
|
-
elsif iN == "exit!"
|
88
|
-
exit!
|
89
|
-
elsif !iN.to_i.between?(1,doc.methods.count) ? methListError(doc) : RubyDoc::CLI::UI.meth_Shuttle(iN, doc)
|
90
|
-
end
|
91
|
-
end
|
92
|
-
#===================Error======================
|
93
|
-
def mainError
|
94
|
-
sleep(0.1)
|
95
|
-
print redH("\n Input Must Be 1 Word or b Try Again ")
|
96
|
-
mainControl
|
97
|
-
end
|
98
|
-
|
99
|
-
def browseError(iN, currentPg, docRange)
|
100
|
-
if currentPg == "Last"
|
101
|
-
choiceError(docRange)
|
102
|
-
browseControl(currentPg, docRange)
|
103
|
-
else
|
104
|
-
print redH("\n Enter a number between 1 and #{docRange.count} n for next or m for main ")
|
105
|
-
browseControl(currentPg, docRange)
|
106
|
-
end
|
107
|
-
end
|
108
|
-
|
109
|
-
def searchError
|
110
|
-
puts "NO MATCH!".red
|
111
|
-
puts "If you are searching for a ".black + "Method" + ", enter the ".black + "Class" + " or".black + "\nModule" + " it belongs to instead. This limitation will be ".black + "\naddressed in future update".black
|
112
|
-
puts "=".black*56
|
113
|
-
|
114
|
-
puts "Example: ".red + "Find".black + " 'reverse'" + " by searching".black + " 'String'"
|
115
|
-
mess = "'Reverse' method will be included in the doc's Methods:# (Additionally feel free to browse all docs)".black
|
116
|
-
puts wrapped(mess, 70).black
|
117
|
-
|
118
|
-
print redH("\n Try A New Word or 'b' To Browse ")
|
119
|
-
mainControl
|
120
|
-
end
|
121
|
-
|
122
|
-
def choiceError(matches)
|
123
|
-
print redH("\n Enter a number between 1 and #{matches.count} or m for main ")
|
124
|
-
choiceControl(matches)
|
125
|
-
end
|
126
|
-
|
127
|
-
def docError(doc)
|
128
|
-
print redH("\n Please enter '1' or 'm' ")
|
129
|
-
docControl(doc)
|
130
|
-
end
|
131
|
-
|
132
|
-
def methError
|
133
|
-
print redH("\n Please enter 'm' to return to main menu ")
|
134
|
-
methControl
|
135
|
-
end
|
136
|
-
|
137
|
-
def methListError(doc)
|
138
|
-
print redH("\n Enter a number between 1 and #{doc.methods.count} or m for main ")
|
139
|
-
methListControl(doc)
|
140
|
-
end
|
141
|
-
#===================Menus======================
|
142
|
-
def mainMenu
|
143
|
-
puts sepR#
|
144
|
-
puts "Enter a ".cyan + "word ".yellow + "associated with the Ruby Language & I will ".cyan
|
145
|
-
puts "try to find a match in my database for you.".cyan
|
146
|
-
sepL#
|
147
|
-
puts "\You can also type".cyan + " 'b'".yellow + " to browse instead.".cyan + " Happy Hunting!".cyan
|
148
|
-
print cyanH("\n If You're Searching... Single Word Inputs Only Please ")
|
149
|
-
end
|
150
|
-
|
151
|
-
def browseMenu
|
152
|
-
puts "To ".cyan + "View An Item ".yellow + "From This List (Enter Doc Number eg.".cyan + "'1'".yellow + ")".cyan
|
153
|
-
puts "To ".cyan + "Browse Next Page ".yellow + "(Enter ".cyan + "'n'".yellow + ")".cyan
|
154
|
-
puts "\nBack to".cyan + " Main Menu".yellow + " (Enter ".cyan + "'m'".yellow + ")\n".cyan
|
155
|
-
print randQ
|
156
|
-
end
|
157
|
-
|
158
|
-
def viewMenu
|
159
|
-
puts "To ".cyan + "View An Item ".yellow + "From This List (Enter ID Number eg.".cyan + "'1'".yellow + ")".cyan
|
160
|
-
puts "\nBack to".cyan + " Main Menu".yellow + " (Enter ".cyan + "'m'".yellow + ")\n".cyan
|
161
|
-
print randQ
|
162
|
-
end
|
163
|
-
|
164
|
-
def docMenu(doc)
|
165
|
-
puts "To ".cyan + "View Methods ".yellow + "For".cyan + " #{doc.name}".yellow + " (Enter ".cyan + "'1'".yellow + ")".cyan
|
166
|
-
puts "To Return To".cyan + " Main Menu".yellow + " (Enter ".cyan + "'m'".yellow + ")\n".cyan
|
167
|
-
print randQ
|
168
|
-
end
|
169
|
-
|
170
|
-
def methMenu
|
171
|
-
puts "To Return To".cyan + " Main Menu".yellow + " (Enter ".cyan + "'m'".yellow + ")\n".cyan
|
172
|
-
print randQ
|
173
|
-
end
|
174
|
-
#===================Input======================
|
175
|
-
def prompt
|
176
|
-
print " >> ".cyan
|
177
|
-
end
|
178
|
-
|
179
|
-
def alphaGets
|
180
|
-
gets.strip.to_s.downcase
|
181
|
-
end
|
182
|
-
#==================Display=====================
|
183
|
-
def outputD(doc, index)
|
184
|
-
puts "#{index + 1}. ".yellow + doc.name.cyan
|
185
|
-
end
|
186
|
-
#==============================================
|
187
|
-
#CANDY
|
188
|
-
#===============Quote Scraper==================
|
189
|
-
def randQ
|
190
|
-
html = Nokogiri::HTML(open("https://fortrabbit.github.io/quotes/"))
|
191
|
-
container = html.search(".row.gutter-l.wrap")
|
192
|
-
|
193
|
-
quotes = container.search("p").map {|quote| quote.text.gsub(/[\n]\s+/, "")}
|
194
|
-
quote = " "+ quotes[rand(0..180)]+ " "
|
195
|
-
wrapped(quote, 55).black
|
196
|
-
end
|
197
|
-
#=============Loading Animation================
|
198
|
-
# Goes above iterator
|
199
|
-
def loading_message
|
200
|
-
puts cyanH(" Loading Database ") + " ☠️"
|
201
|
-
end
|
202
|
-
# Goes inside iterator - last line
|
203
|
-
def loading_animation
|
204
|
-
loading = ""
|
205
|
-
print loading << ". ".cyan if
|
206
|
-
counter == 100 || counter == 200 || counter == 300 || counter == 400 ||
|
207
|
-
counter == 500 || counter == 600 || counter == 700 || counter == 800 ||
|
208
|
-
counter == 900 || counter == 1000 || counter == 1100 || counter == 1200 ||
|
209
|
-
counter == 1300 || counter == 1400 || counter == 1500 || counter == 1600 ||
|
210
|
-
counter == 1700 || counter == 1800 || counter == 1900 || counter == 2000 ||
|
211
|
-
counter == 2100 || counter == 2200 || counter == 2300 || counter == 2320 ||
|
212
|
-
counter == 2340 || counter == 2360 || counter == 2380 || counter == 2400
|
213
|
-
end
|
214
|
-
#=================Separators===================
|
215
|
-
def sepL
|
216
|
-
puts "=".cyan*28 + "=".white*28
|
217
|
-
end
|
218
|
-
|
219
|
-
def sepR
|
220
|
-
"=".white*28 + "=".cyan*28
|
221
|
-
end
|
222
|
-
#==================Strings=====================
|
223
|
-
def wrapped(s, width=78)
|
224
|
-
lines = []
|
225
|
-
line = ""
|
226
|
-
|
227
|
-
s.split(/\s+/).each do |word|
|
228
|
-
if line.size + word.size >= width
|
229
|
-
lines << line
|
230
|
-
line = word
|
231
|
-
elsif line.empty?
|
232
|
-
line = word
|
233
|
-
else
|
234
|
-
line << " " << word
|
235
|
-
end
|
236
|
-
end
|
237
|
-
lines << line if line
|
238
|
-
return lines.join "\n"
|
239
|
-
end#wrap string
|
240
|
-
|
241
|
-
def cyanH(str)
|
242
|
-
str.colorize(color: :white, background: :cyan)
|
243
|
-
end#cyan highlight
|
244
|
-
|
245
|
-
def redH(str)
|
246
|
-
str.colorize(color: :white, background: :red)
|
247
|
-
end#red highlight
|
248
|
-
#=================Signature====================
|
249
|
-
def signature
|
250
|
-
puts "\n"+"=".white*28 + "=".cyan*28
|
251
|
-
puts %q( ALPHA™
|
252
|
-
╦═╗╦ ╦╔╗ ╦ ╦ ╔╦╗╔═╗╔═╗╔═╗
|
253
|
-
╠╦╝║ ║╠╩╗╚╦╝ ║║║ ║║ ╚═╗
|
254
|
-
╩╚═╚═╝╚═╝ ╩ ═╩╝╚═╝╚═╝╚═╝).cyan end
|
255
|
-
#==============================================
|
256
|
-
end
|
257
|
-
|