ruby_doc 1.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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: b09601af432f79494e4d3f0c09b02784dd3f0af1f760e004e9357ab88e042c5b
4
+ data.tar.gz: 76d41e4142c9f62c59032232e2041c71c6bd4fac536773353f9270711a287f4d
5
+ SHA512:
6
+ metadata.gz: a72e71471748518ef5774a953c95ea54c874b15db028c5c4bb391ba655c0e06f6e425eb099f0c5c680886f8cb466f944e37d2bb8282e5c38bb5f27e6c695ff9a
7
+ data.tar.gz: 596a152273eaa76311f7a480761351535c429fc155db81e355d18025bf96073fc57dffe971b4a0a73c0978d30739a25cc9b2ea5660c4508c7c984fc74cb7e987
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+ Attack Notes
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at daniel.nunez.nyc@gmail.com. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in ruby_doc.gemspec
6
+ gemspec
@@ -0,0 +1,28 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ ruby_doc (1.0.0)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ colorize (0.8.1)
10
+ mini_portile2 (2.3.0)
11
+ nokogiri (1.8.1)
12
+ mini_portile2 (~> 2.3.0)
13
+ rake (10.5.0)
14
+ require_all (1.5.0)
15
+
16
+ PLATFORMS
17
+ ruby
18
+
19
+ DEPENDENCIES
20
+ bundler (~> 1.16)
21
+ colorize
22
+ nokogiri
23
+ rake (~> 10.0)
24
+ require_all
25
+ ruby_doc!
26
+
27
+ BUNDLED WITH
28
+ 1.16.1
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2018 Alpha Daniel
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,18 @@
1
+ # Alpha Ruby Doc
2
+ [![forthebadge](http://forthebadge.com/images/badges/powered-by-electricity.svg)](http://forthebadge.com)
3
+ [![forthebadge](http://forthebadge.com/images/badges/pretty-risque.svg)](http://forthebadge.com)
4
+
5
+ ## Installation
6
+
7
+ <!--![image](https://i.imgur.com/AeHWQj8.gif) -->
8
+ <img src="https://i.imgur.com/AeHWQj8.gif" alt="image" width="790" height="170">
9
+
10
+ ```
11
+ 01010000 01101111 01101001 01101110 01110100 01110011 00100000 01100110 01101111 01110010 00100000 01100100 01101001 01101100 01101001 01100111 01100101 01101110 01100011 01100101 00100000 01101101 01111001 00100000 01100110 01110010 01101001 01100101 01101110 01100100 00100001 0001010 01000001 01110011 00100000 01100001 00100000 01110010 01100101 01110111 01100001 01110010 01100100 00100000 01101000 01100101 01110010 01100101 00100111 01110011 00100000 01101101 01111001 00100000 01000111 01100101 01101101 00100000 01000100 01100101 01110011 01100011 01110010 01101001 01110000 01110100 01101001 01101111 01101110 00101110 0001010 0001010 01010100 01101000 01101001 01110011 00100000 01110111 01101001 01101100 01101100 00100000 01100010 01100101 00100000 01100001 00100000 01000011 01001100 01001001 00100000 01000111 01100101 01101101 00100000 01110100 01101000 01100001 01110100 00100000 01110011 01100011 01110010 01100001 01110000 01100101 01110011 00100000 01010010 01110101 01100010 01111001 00100000 01100100 01101111 01100011 01110101 01101101 01100101 01101110 01110100 01100001 01110100 01101001 01101111 01101110 00100000 01100001 01101110 01100100 00100000 01100001 01101100 01101100 01101111 01110111 01110011 00100000 01110101 01110011 01100101 01110010 01110011 00100000 01110100 01101111 00100000 01110001 01110101 01101001 01100011 01101011 01101100 01111001 00100000 01110010 01100101 01100110 01100101 01110010 01100101 01101110 01100011 01100101 00100000 01010010 01110101 01100010 01111001 00100000 01001100 01100001 01101110 01100111 01110101 01100001 01100111 01100101 00100000 01101101 01100101 01110100 01101000 01101111 01100100 01110011 00100000 01100001 01101110 01100100 00100000 01100001 01100100 01100100 01101001 01110100 01101001 01101111 01101110 01100001 01101100 00100000 01101001 01101110 01100110 01101111 01110010 01101101 01100001 01110100 01101001 01101111 01101110 00101110 00100000 01010100 01101000 01101001 01110011 00100000 01110111 01101001 01101100 01101100 00100000 01100010 01100101 00100000 01110100 01101000 01100101 00100000 01100110 01101001 01110010 01110011 01110100 00100000 01101001 01101110 00100000 01100001 00100000 01110011 01100101 01110010 01101001 01100101 01110011 00100000 01101111 01100110 00100000 01000111 01100101 01101101 01110011 00100000 01110100 01101000 01100001 01110100 00100000 01100001 01100011 01100011 01101111 01101101 01110000 01101100 01101001 01110011 01101000 00100000 01110100 01101000 01100101 00100000 01110011 01100001 01101101 01100101 00100000 01100110 01101111 01110010 00100000 01101111 01110100 01101000 01100101 01110010 00100000 01101100 01100001 01101110 01100111 01110101 01100001 01100111 01100101 01110011 00101110 0001010 0001010 01000011 01101000 01100101 01100011 01101011 00100000 01000010 01100001 01100011 01101011 00100000 01010011 01101111 01101111 01101110 00101100 0001010 00101101 01000001 01101100 01110000 01101000 01100001 01000100 01100001 01101110 01101001 01100101 01101100
12
+ ```
13
+
14
+ ## But Seriously .... Check Back Soon
15
+
16
+ ![image](https://images.huffingtonpost.com/2013-08-23-tumblr_m08celcrnT1r3isxuo1_500.gif)
17
+
18
+
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+ task :default => :spec
@@ -0,0 +1,9 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require_relative '../lib/environment'
5
+
6
+ require "irb"
7
+
8
+ IRB.start(__FILE__)
9
+
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+ require_relative '../lib/environment'
3
+
4
+ RubyDoc::CLI.iLoad
5
+
6
+
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,11 @@
1
+ #===========Requires==========
2
+ require 'require_all'
3
+ require 'colorize'
4
+ require 'pry'
5
+ # require_all 'bin'
6
+ require_all 'lib'
7
+ #===========Scraping==========
8
+ require 'open-uri'
9
+ require 'nokogiri'
10
+ #===========Patches===========
11
+ def x; exit!; end #Quit Exit
@@ -0,0 +1,184 @@
1
+ module DataExtras
2
+ #==================important===================
3
+ #@all set/get maker
4
+ def self.extended(base)
5
+ base.class_variable_set(:@@all, [])
6
+ end
7
+
8
+ def all
9
+ self.class_variable_get(:@@all)
10
+ end
11
+
12
+ #UIExtras Shuttles
13
+ def self.uie
14
+ RubyDoc::CLI::UI
15
+ end
16
+
17
+ def uie
18
+ RubyDoc::CLI::UI
19
+ end
20
+
21
+ #PageLister
22
+ def list(page)
23
+ page.each_with_index{|doc, index| uie.outputD(doc, index)}
24
+ end
25
+
26
+ def self.list(page)
27
+ page.each_with_index{|doc, index| uie.outputD(doc, index)}
28
+ end
29
+ #=====================================================================
30
+ #PAGINATOR
31
+ #=====================================================================
32
+ def self.nextPage(currentPg)
33
+ case currentPg
34
+ when "Page1"
35
+ page2
36
+ when "Page2"
37
+ page3
38
+ when "Page3"
39
+ page4
40
+ when "Page4"
41
+ last
42
+ end
43
+ end
44
+ #================================Page 1===============================
45
+ def paginateALL
46
+ uie.sepL#
47
+ list(Doc.all[0..499])
48
+ puts uie.sepR#
49
+
50
+ uie.browseMenu#
51
+ uie.browseControl("Page1", Doc.all[0..499])#
52
+ end
53
+ #================================Page 2===============================
54
+ def self.page2
55
+ uie.sepL#
56
+ list(Doc.all[500..999])
57
+ puts uie.sepR#
58
+
59
+ uie.browseMenu#
60
+ uie.browseControl("Page2", Doc.all[500..999])#
61
+ end
62
+ #================================Page 3===============================
63
+ def self.page3
64
+ uie.sepL#
65
+ list(Doc.all[1000..1499])
66
+ puts uie.sepR#
67
+
68
+ uie.browseMenu#
69
+ uie.browseControl("Page3", Doc.all[1000..1499])#
70
+ end
71
+ #================================Page 4===============================
72
+ def self.page4
73
+ uie.sepL#
74
+ list(Doc.all[1500..1999])
75
+ puts uie.sepR#
76
+
77
+ uie.browseMenu#
78
+ uie.browseControl("Page4", Doc.all[1500..1999])#
79
+ end
80
+ #===============================Page Last=============================
81
+ def self.last
82
+ uie.sepL#
83
+ list(Doc.all[2000..Doc.all.length])
84
+ puts uie.sepR#
85
+
86
+ uie.viewMenu#
87
+ uie.browseControl("Last", Doc.all[2000..Doc.all.length])#
88
+ end
89
+ #==============================Display Doc============================
90
+ def display(doc)
91
+ Scraper.loadDocPage(doc)#Load
92
+
93
+ uie.sepL#
94
+ puts "Title: ".cyan + doc.name.upcase
95
+ puts "Type: ".cyan + doc.type.upcase
96
+ puts "\nDescription:".cyan
97
+ description = doc.description
98
+ puts uie.wrapped(description, 55)
99
+ puts "\nMethods: ".cyan + "#{doc.methods.count}".yellow
100
+ puts "Source: #{doc.url}".red
101
+ puts uie.sepR#
102
+
103
+ uie.docMenu(doc)#
104
+ uie.docControl(doc)#
105
+ end
106
+ #==============================List Meths=============================
107
+ def listMeths(doc)
108
+ uie.sepL#
109
+ doc.methods.each_with_index do |meth, index|
110
+ puts "#{index + 1}. ".yellow + meth.cyan
111
+ end
112
+ puts uie.sepR#
113
+
114
+ uie.viewMenu#
115
+ uie.methListControl(doc)#
116
+ end
117
+ #=============================Display Meth============================
118
+ def displayMeth(byName)
119
+ meth = Meth.find(byName)
120
+ Scraper.loadMethPage(meth)#Load
121
+
122
+ uie.sepL#
123
+ puts "Title: ".cyan + meth.name.upcase
124
+ puts "Type: ".cyan + meth.type.upcase
125
+ puts "\nDescription:".cyan
126
+ description = meth.description
127
+ puts uie.wrapped(description, 55)
128
+ puts "\nSource: #{meth.url}".red
129
+ puts uie.sepR#
130
+
131
+ uie.methMenu#
132
+ uie.methControl#
133
+
134
+ RubyDoc::CLI.start if iN == "m"
135
+ end
136
+ #=============================SUPER SEARCH============================
137
+ def superSEARCH(name)
138
+ uie.sepL#
139
+ matches = Doc.all.find_all{|doc| doc.name.downcase.include?(name)}
140
+
141
+ uie.searchControl(matches)#
142
+ puts uie.sepR#
143
+
144
+ uie.viewMenu#
145
+ uie.choiceControl(matches)#
146
+ end
147
+ =begin
148
+ # NOTES: For now this only searches all doc objects (iterating Doc.all)
149
+ I would like to improve this to also search through all Meth objects.
150
+ The issue here explained below...
151
+
152
+ Population of all methods can only be done through scraping each individual
153
+ doc page for all its meth urls. In this site, methods are spread out
154
+ and not available in their entirety, in a singular container or list.
155
+
156
+ Roadmap: In this CLI I pre-load all docs through Scraper.loadDOCS in
157
+ environment.rb before my exec is ran. When user first lands at UI.greeting
158
+ all docs (objects) are already loaded.
159
+
160
+ To initiate the scrape I need to retrieve a method for instantiation,
161
+ I pass in a Doc class object's url attribute. Since, as previously stated,
162
+ ALL methods do not live in one place... The logical solution would be to
163
+ iterate through Doc.all, pass (obj).url to block and call Scraper.load_doc_page()
164
+ passing in every iteration. This would essentially instantiate meth objects
165
+ for all methods included on all doc pages.
166
+
167
+ 2 big issues arise with this fact. The first and most important URI will not
168
+ let me iterate and open each page (redirection open loop error). 2nd,
169
+ even if we did we would be opening, scraping, and iterating through
170
+ 2403 different site pages. As you can imagine this would not be practical
171
+
172
+ Plan for improvement:
173
+ I will be researching a way to patch this error so as to allow the iteration
174
+ and if successful decide on implementation based on run time.
175
+
176
+ If unsuccessful I will be looking into changing my scrapers to point to
177
+ http://ruby-doc.org/ which was my initial plan with this CLI. As this is
178
+ my very first CLI the layout of this site was a bit intimidating at first glance
179
+ as far as scraping successfully. At the completetion of this CLI I am now
180
+ a lot more confident in my abilities so this will most likely be the way
181
+ I go.
182
+ =end
183
+ #=====================================================================
184
+ end
@@ -0,0 +1,20 @@
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
+ def self.find(name)
17
+ self.all.find{|doc| doc.name.downcase == name.downcase}
18
+ end
19
+ #==========================================================
20
+ end
@@ -0,0 +1,18 @@
1
+ class Meth
2
+ #==================modules=====================
3
+ extend DataExtras #sets/get @@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
@@ -0,0 +1,81 @@
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
@@ -0,0 +1,20 @@
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
+
@@ -0,0 +1,28 @@
1
+ module RubyDoc::CLI
2
+ #==================modules=====================
3
+ class UI
4
+ extend UIExtras#
5
+ #inheriting: mainMenu, mainControl
6
+ extend DataExtras
7
+ #inheriting: paginateALL, superSEARCH(),
8
+ #displayMeth(), display()
9
+ #==============================================
10
+ def self.greeting
11
+ mainMenu#
12
+ mainControl#
13
+ end
14
+
15
+ def self.main_Shuttle(iN)
16
+ iN == "b" ? paginateALL : superSEARCH(iN)
17
+ end
18
+
19
+ def self.search_Shuttle(iN, matches)
20
+ iN == "m" ? greeting : display(matches[iN.to_i-1])
21
+ end
22
+
23
+ def self.meth_Shuttle(iN, doc)
24
+ displayMeth(doc.methods[iN.to_i-1])
25
+ end
26
+ #==============================================
27
+ end
28
+ end
@@ -0,0 +1,247 @@
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
+ end
26
+ # else
27
+ !iN.to_i.between?(1,docRange.count) ? browseError(iN, currentPg, docRange) : Doc.display(docRange[iN.to_i-1])
28
+ end
29
+
30
+ def searchControl(matches)
31
+ matches == [] ? searchError : matches.each_with_index{|doc, index| outputD(doc, index)}
32
+ end
33
+
34
+ def choiceControl(matches)
35
+ prompt
36
+ iN = alphaGets
37
+
38
+ if iN == "m"
39
+ main
40
+ elsif !iN.to_i.between?(1,matches.count)
41
+ choiceError(matches)
42
+ else
43
+ RubyDoc::CLI::UI.search_Shuttle(iN, matches)
44
+ end
45
+ end
46
+
47
+ def docControl(doc)
48
+ prompt
49
+ iN = alphaGets
50
+
51
+ case iN
52
+ when "1"
53
+ Doc.listMeths(doc)
54
+ when "m"
55
+ main
56
+ else
57
+ docError(doc)
58
+ end
59
+ end
60
+
61
+ def methControl
62
+ prompt
63
+ iN = alphaGets
64
+
65
+ case iN
66
+ when "m"
67
+ main
68
+ else
69
+ methError
70
+ end
71
+ end
72
+
73
+ def methListControl(doc)
74
+ prompt
75
+ iN = alphaGets
76
+
77
+ if iN == "m"
78
+ main
79
+ elsif !iN.to_i.between?(1,doc.methods.count) ? methListError(doc) : RubyDoc::CLI::UI.meth_Shuttle(iN, doc)
80
+ end
81
+ end
82
+ #===================Error======================
83
+ def mainError
84
+ sleep(0.1)
85
+ print redH("\n Input Must Be 1 Word or b Try Again ")
86
+ mainControl
87
+ end
88
+
89
+ def browseError(iN, currentPg, docRange)
90
+ if currentPg == "Last"
91
+ choiceError(docRange)
92
+ browseControl(currentPg, docRange)
93
+ else
94
+ print redH("\n Enter a number between 1 and #{docRange.count} n for next or m for main ")
95
+ browseControl(currentPg, docRange)
96
+ end
97
+ end
98
+
99
+ def searchError
100
+ puts "NO MATCH!".red
101
+ 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
102
+ puts "=".black*56
103
+
104
+ puts "Example: ".red + "Find".black + " 'reverse'" + " by searching".black + " 'String'"
105
+ mess = "'Reverse' method will be included in the doc's Methods:# (Additionally feel free to browse all docs)".black
106
+ puts wrapped(mess, 70).black
107
+
108
+ print redH("\n Try A New Word or 'b' To Browse ")
109
+ mainControl
110
+ end
111
+
112
+ def choiceError(matches)
113
+ print redH("\n Enter a number between 1 and #{matches.count} or m for main ")
114
+ choiceControl(matches)
115
+ end
116
+
117
+ def docError(doc)
118
+ print redH("\n Please enter '1' or 'm' ")
119
+ docControl(doc)
120
+ end
121
+
122
+ def methError
123
+ print redH("\n Please enter 'm' to return to main menu ")
124
+ methControl
125
+ end
126
+
127
+ def methListError(doc)
128
+ print redH("\n Enter a number between 1 and #{doc.methods.count} or m for main ")
129
+ methListControl(doc)
130
+ end
131
+ #===================Menus======================
132
+ def mainMenu
133
+ puts sepR#
134
+ puts "Enter a ".cyan + "word ".yellow + "associated with the Ruby Language & I will ".cyan
135
+ puts "try to find a match in my database for you.".cyan
136
+ sepL#
137
+ puts "\You can also type".cyan + " 'b'".yellow + " to browse instead.".cyan + " Happy Hunting!".cyan
138
+ print cyanH("\n If You're Searching... Single Word Inputs Only Please ")
139
+ end
140
+
141
+ def browseMenu
142
+ puts "To ".cyan + "View An Item ".yellow + "From This List (Enter Doc Number eg.".cyan + "'1'".yellow + ")".cyan
143
+ puts "To ".cyan + "Browse Next Page ".yellow + "(Enter ".cyan + "'n'".yellow + ")".cyan
144
+ puts "\nBack to".cyan + " Main Menu".yellow + " (Enter ".cyan + "'m'".yellow + ")\n".cyan
145
+ print randQ
146
+ end
147
+
148
+ def viewMenu
149
+ puts "To ".cyan + "View An Item ".yellow + "From This List (Enter ID Number eg.".cyan + "'1'".yellow + ")".cyan
150
+ puts "\nBack to".cyan + " Main Menu".yellow + " (Enter ".cyan + "'m'".yellow + ")\n".cyan
151
+ print randQ
152
+ end
153
+
154
+ def docMenu(doc)
155
+ puts "To ".cyan + "View Methods ".yellow + "For".cyan + " #{doc.name}".yellow + " (Enter ".cyan + "'1'".yellow + ")".cyan
156
+ puts "To Return To".cyan + " Main Menu".yellow + " (Enter ".cyan + "'m'".yellow + ")\n".cyan
157
+ print randQ
158
+ end
159
+
160
+ def methMenu
161
+ puts "To Return To".cyan + " Main Menu".yellow + " (Enter ".cyan + "'m'".yellow + ")\n".cyan
162
+ print randQ
163
+ end
164
+ #===================Input======================
165
+ def prompt
166
+ print " >> ".cyan
167
+ end
168
+
169
+ def alphaGets
170
+ gets.strip.to_s.downcase
171
+ end
172
+ #==================Display=====================
173
+ def outputD(doc, index)
174
+ puts "#{index + 1}. ".yellow + doc.name.cyan
175
+ end
176
+ #==============================================
177
+ #CANDY
178
+ #===============Quote Scraper==================
179
+ def randQ
180
+ html = Nokogiri::HTML(open("https://fortrabbit.github.io/quotes/"))
181
+ container = html.search(".row.gutter-l.wrap")
182
+
183
+ quotes = container.search("p").map {|quote| quote.text.gsub(/[\n]\s+/, "")}
184
+ quote = " "+ quotes[rand(0..180)]+ " "
185
+ wrapped(quote, 55).black
186
+ end
187
+ #=============Loading Animation================
188
+ # Goes above iterator
189
+ def loading_message
190
+ puts cyanH(" Loading Database ") + " ☠️"
191
+ end
192
+ # Goes inside iterator - last line
193
+ def loading_animation
194
+ loading = ""
195
+ print loading << ". ".cyan if
196
+ counter == 100 || counter == 200 || counter == 300 || counter == 400 ||
197
+ counter == 500 || counter == 600 || counter == 700 || counter == 800 ||
198
+ counter == 900 || counter == 1000 || counter == 1100 || counter == 1200 ||
199
+ counter == 1300 || counter == 1400 || counter == 1500 || counter == 1600 ||
200
+ counter == 1700 || counter == 1800 || counter == 1900 || counter == 2000 ||
201
+ counter == 2100 || counter == 2200 || counter == 2300 || counter == 2320 ||
202
+ counter == 2340 || counter == 2360 || counter == 2380 || counter == 2400
203
+ end
204
+ #=================Separators===================
205
+ def sepL
206
+ puts "=".cyan*28 + "=".white*28
207
+ end
208
+
209
+ def sepR
210
+ "=".white*28 + "=".cyan*28
211
+ end
212
+ #==================Strings=====================
213
+ def wrapped(s, width=78)
214
+ lines = []
215
+ line = ""
216
+
217
+ s.split(/\s+/).each do |word|
218
+ if line.size + word.size >= width
219
+ lines << line
220
+ line = word
221
+ elsif line.empty?
222
+ line = word
223
+ else
224
+ line << " " << word
225
+ end
226
+ end
227
+ lines << line if line
228
+ return lines.join "\n"
229
+ end#wrap string
230
+
231
+ def cyanH(str)
232
+ str.colorize(color: :white, background: :cyan)
233
+ end#cyan highlight
234
+
235
+ def redH(str)
236
+ str.colorize(color: :white, background: :red)
237
+ end#red highlight
238
+ #=================Signature====================
239
+ def signature
240
+ puts "\n"+"=".white*28 + "=".cyan*28
241
+ puts %q( ALPHA™
242
+ ╦═╗╦ ╦╔╗ ╦ ╦ ╔╦╗╔═╗╔═╗╔═╗
243
+ ╠╦╝║ ║╠╩╗╚╦╝ ║║║ ║║ ╚═╗
244
+ ╩╚═╚═╝╚═╝ ╩ ═╩╝╚═╝╚═╝╚═╝).cyan end
245
+ #==============================================
246
+ end
247
+
@@ -0,0 +1,3 @@
1
+ module RubyDoc
2
+ VERSION = "1.0.0"
3
+ end
@@ -0,0 +1,29 @@
1
+
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "ruby_doc/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "ruby_doc"
8
+ spec.version = RubyDoc::VERSION
9
+ spec.authors = ["Daniel Nunez"]
10
+ spec.email = ["daniel.nunez.nyc@gmail.com"]
11
+
12
+ spec.summary = %q{A CLI Gem that scrapes Ruby documentation for quick referencing. This will be the first in a series of Gems that accomplish the same for other languages.}
13
+ spec.description = %q{Ever get tired of leaving your editor/environment to google a method? This gem aims to make Ruby referencing quick and more importantly, LOCAL! Enjoy.}
14
+ spec.homepage = "https://github.com/AlphaDaniel/alpha-ruby_docs"
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
18
+ f.match(%r{^(test|spec|features)/})
19
+ end
20
+
21
+ spec.executables = ['ruby_doc']
22
+ spec.require_paths = ["lib"]
23
+
24
+ spec.add_development_dependency "bundler", "~> 1.16"
25
+ spec.add_development_dependency "rake", "~> 10.0"
26
+ spec.add_development_dependency "require_all"
27
+ spec.add_development_dependency "colorize"
28
+ spec.add_development_dependency "nokogiri"
29
+ end
metadata ADDED
@@ -0,0 +1,137 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ruby_doc
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Daniel Nunez
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2018-01-26 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.16'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.16'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: require_all
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: colorize
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: nokogiri
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ description: Ever get tired of leaving your editor/environment to google a method?
84
+ This gem aims to make Ruby referencing quick and more importantly, LOCAL! Enjoy.
85
+ email:
86
+ - daniel.nunez.nyc@gmail.com
87
+ executables:
88
+ - ruby_doc
89
+ extensions: []
90
+ extra_rdoc_files: []
91
+ files:
92
+ - ".gitignore"
93
+ - CODE_OF_CONDUCT.md
94
+ - Gemfile
95
+ - Gemfile.lock
96
+ - LICENSE.txt
97
+ - README.md
98
+ - Rakefile
99
+ - bin/console
100
+ - bin/ruby_doc
101
+ - bin/setup
102
+ - lib/environment.rb
103
+ - lib/ruby_doc/data/data_extras.rb
104
+ - lib/ruby_doc/data/doc.rb
105
+ - lib/ruby_doc/data/meth.rb
106
+ - lib/ruby_doc/data/scrapers.rb
107
+ - lib/ruby_doc/ui/CLI.rb
108
+ - lib/ruby_doc/ui/UI.rb
109
+ - lib/ruby_doc/ui/ui_extras.rb
110
+ - lib/ruby_doc/version.rb
111
+ - ruby_doc.gemspec
112
+ homepage: https://github.com/AlphaDaniel/alpha-ruby_docs
113
+ licenses:
114
+ - MIT
115
+ metadata: {}
116
+ post_install_message:
117
+ rdoc_options: []
118
+ require_paths:
119
+ - lib
120
+ required_ruby_version: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ required_rubygems_version: !ruby/object:Gem::Requirement
126
+ requirements:
127
+ - - ">="
128
+ - !ruby/object:Gem::Version
129
+ version: '0'
130
+ requirements: []
131
+ rubyforge_project:
132
+ rubygems_version: 2.7.3
133
+ signing_key:
134
+ specification_version: 4
135
+ summary: A CLI Gem that scrapes Ruby documentation for quick referencing. This will
136
+ be the first in a series of Gems that accomplish the same for other languages.
137
+ test_files: []