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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ce6c50fa59859ab477b3a2bdd0af629adabd6492eb68d988851868893fdbc73a
4
- data.tar.gz: 1dbb4fe3ccb1eca4f707e46fbed8a5de498a5b3403e6280ff8388f1a41450d92
3
+ metadata.gz: 9f6ff52d91baa724d38c4466abfc16202893d12938de22d9f1e81ce08eea6a3e
4
+ data.tar.gz: ddf9fc4ccdc6c317eee458d0db2453a028896f7b60d98dc81a601a4842768f5c
5
5
  SHA512:
6
- metadata.gz: d3b691614a0b80c69e82a0240541c8a2ca7045e9e0d673c8762431177106ca5fd76c14cac63d62d7d82bad82a769825d4543f066abf56093fdb6c74b250a5d7b
7
- data.tar.gz: 56d76686e5aea2b98c2630d0aaf3d154f3bbf43f2bb54d0a273b196e8783f3b2d079b46d2664599bfd8347d72f65103721a58960de8a3a4edb4b3ce4e68906a6
6
+ metadata.gz: 13b4329220e11292910429d10b5ee110e9e5383a6a75373aca16e87a04ac8cc9ee030a5233ab7960502147b4a70abb13ebb91166bef719f89523c54198fb3dab
7
+ data.tar.gz: 2cefcb41740d450e7ef7e296b957e0a5ef6362d549cd8f8d58cadccedfddb177bb7ff2ac16d6971ff614b7bc49e52efc35124cb37f28d942ff064ee25383d418
data/.gitignore CHANGED
@@ -6,4 +6,4 @@
6
6
  /pkg/
7
7
  /spec/reports/
8
8
  /tmp/
9
- Attack Notes
9
+ private
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- ruby_doc (1.0.5)
4
+ ruby_doc (2.0.0)
5
5
  colorize (~> 0.8.1)
6
6
  nokogiri (~> 1.8, >= 1.8.1)
7
7
 
@@ -13,7 +13,7 @@ GEM
13
13
  diff-lcs (1.3)
14
14
  method_source (0.9.0)
15
15
  mini_portile2 (2.3.0)
16
- nokogiri (1.8.1)
16
+ nokogiri (1.8.2)
17
17
  mini_portile2 (~> 2.3.0)
18
18
  pry (0.11.3)
19
19
  coderay (~> 1.1.0)
data/README.md CHANGED
@@ -4,10 +4,9 @@
4
4
  ![](http://forthebadge.com/images/badges/powered-by-electricity.svg)
5
5
  ![](http://forthebadge.com/images/badges/pretty-risque.svg)
6
6
 
7
- ![](https://img.shields.io/badge/Init--Release-Jan--2018-orange.svg)
8
7
  [![Gem Version](https://badge.fury.io/rb/ruby_doc.svg)](https://badge.fury.io/rb/ruby_doc)
9
8
  [![Gem](https://img.shields.io/gem/dt/ruby_doc.svg)](https://rubygems.org/gems/ruby_doc)
10
- ![](https://img.shields.io/badge/gem--series-alpha--docs-blue.svg)
9
+ [![Changelog](https://img.shields.io/badge/change-log-blue.svg)](https://github.com/AlphaDaniel/alpha-ruby_doc/blob/master/changelog.md)
11
10
  [![GitHub last commit](https://img.shields.io/github/last-commit/AlphaDaniel/alpha-ruby_doc.svg)](https://github.com/AlphaDaniel/alpha-ruby_doc/commits/master)
12
11
  [![](https://img.shields.io/badge/A-C-red.svg)](http://a1phacoding.com/)
13
12
 
@@ -26,17 +25,24 @@ Ever get tired of leaving your editor / environment to google a method, or more
26
25
 
27
26
  ![image](https://i.imgur.com/NmincSX.gif)
28
27
  ### Features:
29
- * Search by Doc title
30
- * View related methods
31
- * Browse all Docs (Paginated Output To Terminal)
32
- * Source Links
33
- * Easy Navigation
34
- * Random Dev Quotes (Ok This One Is Just For Fun Lol)
28
+ Search for Ruby Documentation by Class, Module or Method Name
29
+
30
+ Browse all Documentation (Paginated Output To Terminal)
31
+
32
+ ✓ View Descriptions and Syntax
33
+
34
+ ✓ View Source Code
35
+
36
+ ✓ Source Links Provided
37
+
38
+ ✓ Easy Navigation
39
+
40
+ ✓ Random Dev Quotes (For fun and motivation)
35
41
 
36
42
  ### Coming Soon:
37
- * Search by method name ([See Notes](https://github.com/AlphaDaniel/alpha-ruby_doc/blob/master/Notes.md))
38
43
  * Multiple Doc sources
39
- * Display Syntax
44
+ * Save Favorites
45
+ * Add Notes
40
46
 
41
47
  ---
42
48
  ## INSTALLATION
@@ -75,6 +81,10 @@ To exit
75
81
 
76
82
  $ exit!
77
83
 
84
+ To Learn More
85
+
86
+ $ ?
87
+
78
88
  ---
79
89
  ## Contributing
80
90
 
data/Rakefile CHANGED
@@ -1,2 +1,8 @@
1
1
  require "bundler/gem_tasks"
2
2
  task :default => :spec
3
+
4
+ require_relative './config/environment'
5
+
6
+ task :console do
7
+ Pry.start
8
+ end
data/bin/ruby_doc CHANGED
@@ -2,6 +2,6 @@
2
2
  require "bundler/setup"
3
3
  require_relative '../config/environment'
4
4
 
5
- RubyDoc::CLI.iLoad
5
+ RubyDoc::CLI.start_load
6
6
 
7
7
 
data/changelog.md CHANGED
@@ -1,4 +1,14 @@
1
- Unreleased Changes
1
+ v2.0.0 (2018-02-21)
2
+ ------------------
3
+
4
+ * Improved Data Source
5
+ * Feature - Search Methods, Classes, and Modules
6
+ * Feature - Focus Highlight on Classes & Modules in Search Matches
7
+ * Feature - Display Syntax
8
+ * Feature - Display Source Code
9
+ * Added Learn More Option in Main Menu with Changelog & Coming Soon
10
+
11
+ v1.1.5 (2018-02-01)
2
12
  ------------------
3
13
 
4
14
  * Navigation Improved - Exit with (Exit!)
@@ -1,13 +1,19 @@
1
- #===========Requires==========
1
+ #====================Requires===================
2
2
  require 'colorize'
3
3
  require 'open-uri'
4
4
  require 'nokogiri'
5
+ require_relative './patches'
5
6
  require_relative '../lib/ruby_doc/version'
6
- require_relative '../lib/ruby_doc/ui/CLI'
7
- require_relative '../lib/ruby_doc/ui/UI'
8
- require_relative '../lib/ruby_doc/data/scrapers'
9
- require_relative '../lib/ruby_doc/data/meth'
10
- require_relative '../lib/ruby_doc/data/doc'
11
- #===========Testing===========
12
- # require 'pry'
13
- def x; exit!; end #Quit Exit
7
+ #======================Cli======================
8
+ require_relative '../lib/ruby_doc/cli/cli'
9
+ require_relative '../lib/ruby_doc/cli/ui'
10
+ #=====================Data======================
11
+ require_relative '../lib/ruby_doc/data/class'
12
+ require_relative '../lib/ruby_doc/data/method'
13
+ require_relative '../lib/ruby_doc/data/scraper'
14
+ require_relative '../lib/ruby_doc/data/data_processor'
15
+ #====================DataBase===================
16
+ $DocDB = []
17
+ #====================Testing====================
18
+ # Scraper.changelog
19
+ #===============================================
data/config/patches.rb ADDED
@@ -0,0 +1,15 @@
1
+ require_relative './environment'
2
+
3
+ require 'pry'
4
+ #========================pry patches==========================
5
+ #QUICK NEXT PRY
6
+ Pry::Commands.alias_command 'n', 'exit'
7
+ # hit next bind with 'x' instead of 'exit'
8
+ # CUSTOMIZE: replace 'x' in code above with 'your_preference'
9
+ #-------------------------------------------------------------
10
+ #QUICK EXIT
11
+ def x; exit!; end
12
+ # exit pry session with 'x' instead of 'exit!'
13
+ # CUSTOMIZE: replace 'xx' in code above with 'your_preference'
14
+ #=============================================================
15
+
@@ -0,0 +1,16 @@
1
+ module RubyDoc::CLI
2
+ #======================================================
3
+ def self.start_load
4
+ puts "\nThanks For Using ALPHA™ Ruby Docs!".cyan
5
+ puts "One Moment Please As We Set Things Up\n".cyan
6
+ Scraper.load_classes and Scraper.load_methods
7
+ self.start
8
+ end
9
+ #------------------------------------------------------
10
+ def self.start
11
+ UI.signature
12
+ UI.main_menu
13
+ UI.main_control
14
+ end
15
+ #======================================================
16
+ end
@@ -0,0 +1,387 @@
1
+ class UI
2
+ #=================Properties===================
3
+ attr_reader :counter #For Loading Anim
4
+ #===================Input======================
5
+ def self.my_gets
6
+ gets.strip.to_s.downcase
7
+ end
8
+ #==================Control=====================
9
+ def self.main_control
10
+ prompt
11
+ input = my_gets
12
+
13
+ if input.split.size > 1
14
+ main_error
15
+ elsif input == "b"
16
+ paginate("start")
17
+ elsif input == "exit!"
18
+ exit!
19
+ elsif input == "?"
20
+ learn_more
21
+ else
22
+ matches = Processor.search(input)
23
+
24
+ search_error if matches.empty?
25
+ search_list(matches) if matches
26
+ end
27
+ end
28
+
29
+ def self.list_control(matches)
30
+ prompt
31
+ input = my_gets
32
+
33
+ if input == "m"
34
+ RubyDoc::CLI.start
35
+ elsif input == "exit!"
36
+ exit!
37
+ elsif !input.to_i.between?(1,matches.count)
38
+ list_error(matches)
39
+ else
40
+ Processor.load_doc(matches[input.to_i-1])
41
+ end
42
+ list_control(matches)
43
+ end
44
+
45
+ def self.display_class_control(doc)
46
+ prompt
47
+ input = my_gets
48
+
49
+ case input
50
+ when "1"
51
+ method_list(doc)
52
+ when "m"
53
+ RubyDoc::CLI.start
54
+ when "exit!"
55
+ exit!
56
+ else
57
+ display_class_error(doc)
58
+ end
59
+ end
60
+
61
+ def self.display_method_control
62
+ prompt
63
+ input = my_gets
64
+
65
+ case input
66
+ when "m"
67
+ RubyDoc::CLI.start
68
+ when "exit!"
69
+ exit!
70
+ else
71
+ display_method_error
72
+ end
73
+ end
74
+
75
+ def self.browse_control(identifier, page)
76
+ prompt
77
+ input = my_gets
78
+
79
+ case input
80
+ when "n"
81
+ paginate(identifier)
82
+ when "m"
83
+ RubyDoc::CLI.start
84
+ when "exit!"
85
+ exit!
86
+ end
87
+
88
+ if !input.to_i.between?(1,page.count)
89
+ browse_error(input, identifier, page)
90
+ else
91
+ Processor.load_doc(page[input.to_i-1])
92
+ end
93
+ end
94
+ #==================Display=====================
95
+ def self.search_list(matches)
96
+ UI.sepL
97
+ matches.each_with_index do |doc, index|
98
+
99
+ if doc.type == "Class" || doc.type == "Module"
100
+ li = ["#{index + 1}.".yellow, doc.name.light_cyan]
101
+ else
102
+ li = ["#{index + 1}.".yellow, doc.name.cyan]
103
+ end
104
+
105
+ puts li.join(" ")
106
+ end
107
+ puts sepR
108
+ puts "Classes and Modules are".cyan + " Highlighted".light_cyan
109
+ puts sepR
110
+
111
+ list_menu(matches)
112
+ list_control(matches)
113
+ end
114
+
115
+ def self.display_class(doc)
116
+ UI.sepL
117
+ puts "TITLE: ".cyan + doc.name.upcase
118
+ puts "TYPE: ".cyan + doc.type.upcase
119
+ puts "\nDESCRIPTION:".cyan
120
+ puts doc.description
121
+ puts "Methods: ".cyan + "#{doc.methods.count}".yellow
122
+ puts "Source: #{doc.url}".red
123
+ puts sepR
124
+
125
+ display_class_menu(doc)
126
+ display_class_control(doc)
127
+ end
128
+
129
+ def self.method_list(doc)
130
+ puts sepR
131
+ doc.methods.each_with_index do |method, index|
132
+
133
+ if !method.nil?
134
+ li = ["#{index + 1}.".yellow, method.name.cyan]
135
+ puts li.join(" ")
136
+ end
137
+
138
+ end
139
+ puts sepR
140
+
141
+ list_menu(doc.methods)
142
+ list_control(doc.methods)
143
+ end
144
+
145
+ def self.display_method(doc)
146
+ UI.sepL
147
+ puts "Title: ".cyan + doc.name.upcase
148
+ puts "Type: ".cyan + doc.type.upcase
149
+ puts "\nDescription:".cyan
150
+ puts doc.doc
151
+ puts "Source: #{doc.url}".red
152
+ puts sepR
153
+
154
+ #-----------future fix------------#
155
+ # description = doc.doc
156
+ # puts uie.wrapped(description, 55)
157
+ #-----------future fix------------#
158
+
159
+ display_method_menu
160
+ display_method_control
161
+ end
162
+
163
+ def self.paginate(identifier)
164
+
165
+ case identifier
166
+ when "start"
167
+ Processor.page1
168
+ when "Page1"
169
+ Processor.page2
170
+ when "Page2"
171
+ Processor.page3
172
+ when "Page3"
173
+ Processor.last
174
+ end
175
+
176
+ end
177
+
178
+ def self.browse_list(page, identifier)
179
+ puts sepL
180
+ page.each_with_index do |doc, index|
181
+
182
+ if doc.type == "Class" || doc.type == "Module"
183
+ li = ["#{index + 1}.".yellow, doc.name.light_cyan]
184
+ else
185
+ li = ["#{index + 1}.".yellow, doc.name.cyan]
186
+ end
187
+
188
+ puts li.join(" ")
189
+ end
190
+
191
+ if identifier == "Last"
192
+ puts sepR
193
+ puts "End of List".red
194
+ end
195
+ puts sepR
196
+
197
+ last_page_menu(page) if identifier == "Last"
198
+ browse_menu(page) if !(identifier == "Last")
199
+
200
+ browse_control(identifier, page)
201
+ end
202
+
203
+ def self.learn_more
204
+ puts "\nCOMING SOON".cyan
205
+ puts "=".black*56
206
+ puts Scraper.coming_soon
207
+
208
+ puts "\nCHANGELOG".cyan
209
+ puts "=".black*56
210
+ puts Scraper.changelog
211
+
212
+ main_menu
213
+ main_control
214
+ end
215
+ #===================Menus======================
216
+ def self.main_menu
217
+ puts sepR#
218
+ puts "Enter a ".cyan + "word ".yellow + "associated with the Ruby Language & I will ".cyan
219
+ puts "try to find a match in my database for you.".cyan
220
+ sepL#
221
+ puts "\You can also enter".cyan + " 'b'".yellow + " to browse instead.".cyan + " Happy Hunting!".cyan
222
+ puts "=".black*56
223
+ puts "Enter '?' to Learn More about Alpha Ruby-Doc".black
224
+ print cyanH("\n If You're Searching... Single Word Inputs Only Please ")
225
+ end
226
+
227
+ def self.list_menu(matches)
228
+ puts "To ".cyan + "View ".yellow + "(Enter ".cyan + "#".yellow + ")".cyan + " eg. #{matches.count.to_s} for #{matches[matches.count-2].name}".black
229
+ puts "To return to".cyan + " Main Menu".yellow + " (Enter ".cyan + "'m'".yellow + ")".cyan
230
+ puts "To".cyan + " Leave".yellow + " (".cyan + "'exit!'".yellow + ")\n".cyan
231
+ print randQ
232
+ end
233
+
234
+ def self.display_class_menu(doc)
235
+ puts "To ".cyan + "View Methods ".yellow + "For".cyan + " #{doc.name}".yellow + " (Enter ".cyan + "'1'".yellow + ")".cyan
236
+ puts "To Return To".cyan + " Main Menu".yellow + " (Enter ".cyan + "'m'".yellow + ")".cyan
237
+ puts "To".cyan + " Leave".yellow + " (".cyan + "'exit!'".yellow + ")\n".cyan
238
+ print randQ
239
+ end
240
+
241
+ def self.display_method_menu
242
+ puts "To Return To".cyan + " Main Menu".yellow + " (Enter ".cyan + "'m'".yellow + ")".cyan
243
+ puts "To".cyan + " Leave".yellow + " (".cyan + "'exit!'".yellow + ")\n".cyan
244
+ print randQ
245
+ end
246
+
247
+ def self.browse_menu(page)
248
+ puts "To ".cyan + "View ".yellow + "(Enter ".cyan + "#".yellow + ")".cyan + " eg. #{page.count.to_s} for #{page[page.count-1].name}".black
249
+ puts "To ".cyan + "Browse Next Page ".yellow + "(Enter ".cyan + "'n'".yellow + ")".cyan
250
+ puts "To Return To".cyan + " Main Menu".yellow + " (Enter ".cyan + "'m'".yellow + ")".cyan
251
+ puts "To".cyan + " Leave".yellow + " (".cyan + "'exit!'".yellow + ")\n".cyan
252
+ print randQ
253
+ end
254
+
255
+ def self.last_page_menu(page)
256
+ puts "To ".cyan + "View ".yellow + "(Enter ".cyan + "#".yellow + ")".cyan + " eg. #{page.count.to_s} for #{page[page.count-1].name}".black
257
+ puts "To Return To".cyan + " Main Menu".yellow + " (Enter ".cyan + "'m'".yellow + ")".cyan
258
+ puts "To".cyan + " Leave".yellow + " (".cyan + "'exit!'".yellow + ")\n".cyan
259
+ print randQ
260
+ end
261
+ #===================Error======================
262
+ def self.main_error
263
+ sleep(0.1)
264
+ print redH("\n Input Must Be 1 Word, 'b' to browse, or 'exit!' to leave ")
265
+ main_control
266
+ end
267
+
268
+ def self.search_error
269
+ puts "\nNO CIGAR!".red
270
+ puts "I couldn't find what you're looking for.".black
271
+ puts "How about trying a Ruby ".black + "Method" + ", ".black + "Class" + " or ".black + "Module" + " name.".black
272
+ puts "=".black*56
273
+
274
+ puts "\nNOT SURE?".red
275
+ puts "You can always browse with ".black + "'b'" + " & learn something new.".black + ":)"
276
+ puts "=".black*56
277
+
278
+ print redH("\n Try a new word, enter 'b' to browse, or 'exit!' to leave ")
279
+ main_control
280
+ end
281
+
282
+ def self.list_error(matches)
283
+ print redH("\n Enter selection number, 'm' for main or 'exit!' to leave ")
284
+ end
285
+
286
+ def self.nil_error
287
+ print redH("\n Enter selection number, 'm' for main or 'exit!' to leave ")
288
+ end
289
+
290
+ def self.display_class_error(doc)
291
+ print redH("\n Please enter '1' to view methods, 'm' for main, or 'exit!' to leave ")
292
+ display_class_control(doc)
293
+ end
294
+
295
+ def self.display_method_error
296
+ print redH("\n Please enter 'm' for main menu or 'exit!' to leave ")
297
+ display_method_control
298
+ end
299
+
300
+ def self.browse_error(input, identifier, page)
301
+ if identifier == "Last"
302
+ list_error(page)
303
+ browse_control(identifier, page)
304
+ else
305
+ browse_list_error(page)
306
+ browse_control(identifier, page)
307
+ end
308
+ end
309
+
310
+ def self.browse_list_error(page)
311
+ print redH("\n Enter # to view, 'n' for next page 'm' for main or 'exit!' to leave ")
312
+ end
313
+ #==============================================
314
+ #CANDY
315
+ #===============Quote Scraper==================
316
+ def self.randQ
317
+ html = Nokogiri::HTML(open("https://fortrabbit.github.io/quotes/"))
318
+ container = html.search(".row.gutter-l.wrap")
319
+
320
+ quotes = container.search("p").map {|quote| quote.text.gsub(/[\n]\s+/, "")}
321
+ quote = " "+ quotes[rand(0..180)]+ " "
322
+ wrapped(quote, 55).black
323
+ end
324
+ #=============Loading Animation================
325
+ # Goes above iterator
326
+ def self.loading_message
327
+ puts cyanH(" Loading Database ") + " ☠️"
328
+ end
329
+ # Goes inside iterator - last line
330
+ def self.loading_animation
331
+ loading = ""
332
+ print loading << ". ".cyan if
333
+ @counter == 50 || @counter == 100 || @counter == 150 || @counter == 200 ||
334
+ @counter == 250 || @counter == 300 || @counter == 350 || @counter == 400 ||
335
+ @counter == 450 || @counter == 500 || @counter == 550 || @counter == 600 ||
336
+ @counter == 650 || @counter == 700 || @counter == 750 || @counter == 800 ||
337
+ @counter == 850 || @counter == 900 || @counter == 950 || @counter == 1000 ||
338
+ @counter == 1150 || @counter == 1200 || @counter == 1250 || @counter == 1300 ||
339
+ @counter == 1350 || @counter == 1400 || @counter == 1450 || @counter == 1500
340
+ end
341
+ #=============Colors/Candy Props===============
342
+ def self.prompt
343
+ print " >> ".cyan
344
+ end
345
+
346
+ def self.sepL
347
+ puts "=".cyan*28 + "=".white*28
348
+ end
349
+
350
+ def self.sepR
351
+ "=".white*28 + "=".cyan*28
352
+ end
353
+
354
+ def self.redH(str)
355
+ str.colorize(color: :white, background: :red)
356
+ end#red highlight
357
+
358
+ def self.cyanH(str)
359
+ str.colorize(color: :white, background: :cyan)
360
+ end#cyan highlight
361
+
362
+ def self.wrapped(s, width=78)
363
+ lines = []
364
+ line = ""
365
+
366
+ s.split(/\s+/).each do |word|
367
+ if line.size + word.size >= width
368
+ lines << line
369
+ line = word
370
+ elsif line.empty?
371
+ line = word
372
+ else
373
+ line << " " << word
374
+ end
375
+ end
376
+ lines << line if line
377
+ return lines.join "\n"
378
+ end #wrap string
379
+ #=================Signature====================
380
+ def self.signature
381
+ puts "\n"+"=".white*28 + "=".cyan*28
382
+ puts %q( ALPHA™
383
+ ╦═╗╦ ╦╔╗ ╦ ╦ ╔╦╗╔═╗╔═╗╔═╗
384
+ ╠╦╝║ ║╠╩╗╚╦╝ ║║║ ║║ ╚═╗
385
+ ╩╚═╚═╝╚═╝ ╩ ═╩╝╚═╝╚═╝╚═╝).cyan end
386
+ #==============================================
387
+ end