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
@@ -0,0 +1,18 @@
|
|
1
|
+
class Klass
|
2
|
+
#=======================properties================================
|
3
|
+
attr_accessor :type, :name, :url, :short, :description, :methods
|
4
|
+
#-----------------------------------------------------------------
|
5
|
+
@@all = []
|
6
|
+
def self.all; @@all; end
|
7
|
+
#=================================================================
|
8
|
+
# count = 125
|
9
|
+
def initialize(type, name, url)
|
10
|
+
self.type = type
|
11
|
+
self.name = name
|
12
|
+
self.url = url
|
13
|
+
@@all << self
|
14
|
+
self.methods = []
|
15
|
+
end
|
16
|
+
#=================================================================
|
17
|
+
end
|
18
|
+
|
@@ -0,0 +1,35 @@
|
|
1
|
+
class Processor
|
2
|
+
#=============================Browse Pages============================
|
3
|
+
def self.page1
|
4
|
+
UI.browse_list($DocDB[0..499], "Page1")
|
5
|
+
end
|
6
|
+
|
7
|
+
def self.page2
|
8
|
+
UI.browse_list($DocDB[500..999], "Page2")
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.page3
|
12
|
+
UI.browse_list($DocDB[1000..1499], "Page3")
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.last
|
16
|
+
UI.browse_list($DocDB[1500..$DocDB.count], "Last")
|
17
|
+
end
|
18
|
+
#===============================Load Doc==============================
|
19
|
+
def self.load_doc(doc)
|
20
|
+
if !doc.nil?
|
21
|
+
Scraper.load_class_doc(doc) if doc.type == "Class" || doc.type == "Module"
|
22
|
+
Scraper.load_method_doc(doc) if doc.type == "Method"
|
23
|
+
|
24
|
+
UI.display_class(doc) if doc.type == "Class" || doc.type == "Module"
|
25
|
+
UI.display_method(doc) if doc.type == "Method"
|
26
|
+
else
|
27
|
+
UI.nil_error
|
28
|
+
end
|
29
|
+
end
|
30
|
+
#================================SEARCH===============================
|
31
|
+
def self.search(name)
|
32
|
+
matches = $DocDB.find_all{|doc| doc.name.downcase.include?(name)}
|
33
|
+
end
|
34
|
+
#=====================================================================
|
35
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
class Meth
|
2
|
+
#============================================================
|
3
|
+
attr_accessor :type, :name, :url, :doc
|
4
|
+
#------------------------------------------------------------
|
5
|
+
@@all = []
|
6
|
+
def self.all; @@all; end
|
7
|
+
#============================================================
|
8
|
+
# count 1839
|
9
|
+
def initialize(type="n/a", name, url)
|
10
|
+
self.type = type
|
11
|
+
self.name = name
|
12
|
+
self.url = url
|
13
|
+
@@all << self
|
14
|
+
end
|
15
|
+
#============================================================
|
16
|
+
def self.find_by(url)
|
17
|
+
Meth.all.find{|m| m.url == url}
|
18
|
+
end
|
19
|
+
#============================================================
|
20
|
+
end
|
@@ -0,0 +1,139 @@
|
|
1
|
+
class Scraper < UI
|
2
|
+
#===========================Load Classes=================================
|
3
|
+
def self.load_classes
|
4
|
+
@counter = 0 #For Loading anim
|
5
|
+
loading_message#
|
6
|
+
|
7
|
+
html = Nokogiri::HTML(open("https://ruby-doc.org/core-2.4.3/"))
|
8
|
+
icontainer = html.search("#class-index .entries")
|
9
|
+
|
10
|
+
icontainer.search("p").each do |li|
|
11
|
+
name = li.search("a").text
|
12
|
+
url = prefix + li.search("a")[0]["href"]
|
13
|
+
type = li["class"].capitalize
|
14
|
+
|
15
|
+
# assigns - Klass :names, :urls
|
16
|
+
doc = Klass.new(type, name, url) if class_uniq(url)
|
17
|
+
# keeps copy in DocDB
|
18
|
+
$DocDB << doc if doc_uniq(url)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
#===========================Load Methods=================================
|
22
|
+
def self.load_methods
|
23
|
+
html = Nokogiri::HTML(open("https://ruby-doc.org/core-2.4.3/"))
|
24
|
+
icontainer = html.search("#method-index .entries")
|
25
|
+
|
26
|
+
icontainer.search("a").each do |li|
|
27
|
+
name = li.text
|
28
|
+
url = prefix + li["href"]
|
29
|
+
type = "Method"
|
30
|
+
|
31
|
+
# assigns - Method :names, :urls
|
32
|
+
doc = Meth.new("Method", name, url) if method_uniq(url)
|
33
|
+
# keeps copy in DocDB
|
34
|
+
$DocDB << doc if doc_uniq(name)
|
35
|
+
|
36
|
+
@counter += 1 #For Loading anim
|
37
|
+
loading_animation#
|
38
|
+
end
|
39
|
+
end
|
40
|
+
#==========================Load Class Doc================================
|
41
|
+
def self.load_class_doc(doc)
|
42
|
+
html = Nokogiri::HTML(open(doc.url))
|
43
|
+
#------------------------------------------------------------------------
|
44
|
+
# documentation
|
45
|
+
container = html.search("#description")
|
46
|
+
|
47
|
+
short = container.search("p")[0].text + expand
|
48
|
+
|
49
|
+
description = ""
|
50
|
+
container.search("p, pre, h2").each {|p| description << p.text + "\n\n"}
|
51
|
+
|
52
|
+
# assign
|
53
|
+
doc.short = short
|
54
|
+
doc.description = description
|
55
|
+
#------------------------------------------------------------------------
|
56
|
+
# methods
|
57
|
+
methods = html.search("ul.link-list a")
|
58
|
+
|
59
|
+
methods.each do |m|
|
60
|
+
url = doc.url + m["href"]
|
61
|
+
method = Meth.find_by(url)
|
62
|
+
|
63
|
+
doc.methods << method if class_method_uniq(doc, method)
|
64
|
+
end
|
65
|
+
end
|
66
|
+
#=========================Load Method Doc================================
|
67
|
+
def self.load_method_doc(method)
|
68
|
+
html = Nokogiri::HTML(open(method.url))
|
69
|
+
#------------------------------------------------------------------------
|
70
|
+
# documentation
|
71
|
+
selector = "#"+method.url.gsub(/.+#method.{3}/, "")+"-method"
|
72
|
+
|
73
|
+
if html.search("#{selector}").first["class"].include?("method-alias")
|
74
|
+
|
75
|
+
conn = html.search("#{selector}").first.search("a")[1]["href"]
|
76
|
+
rebuild = "#"+ conn.gsub(/.+#method.{3}/, "")+"-method"
|
77
|
+
|
78
|
+
container = html.search(rebuild)[0]
|
79
|
+
|
80
|
+
doc = ""
|
81
|
+
doc << html.search("#{selector} div.aliases").first.text + "\n\n"
|
82
|
+
container.search("p, pre, h2").each {|p| doc << p.text + "\n\n" }
|
83
|
+
|
84
|
+
# assign
|
85
|
+
method.doc = doc
|
86
|
+
else
|
87
|
+
container = html.search(selector)[0]
|
88
|
+
|
89
|
+
doc = ""
|
90
|
+
container.search("p, pre, h2").each {|p| doc << p.text + "\n\n" }
|
91
|
+
|
92
|
+
# assign
|
93
|
+
method.doc = doc
|
94
|
+
end
|
95
|
+
end
|
96
|
+
#=======================================================================#
|
97
|
+
#HELPERS
|
98
|
+
#========================================================================
|
99
|
+
def self.class_uniq(url)
|
100
|
+
Klass.all.none?{|klass| klass.url == url}
|
101
|
+
end
|
102
|
+
|
103
|
+
def self.method_uniq(url)
|
104
|
+
Meth.all.none?{|method| method.url == url}
|
105
|
+
end
|
106
|
+
|
107
|
+
def self.doc_uniq(url)
|
108
|
+
$DocDB.none?{|doc| doc.url == url}
|
109
|
+
end
|
110
|
+
|
111
|
+
def self.class_method_uniq(doc, method)
|
112
|
+
doc.methods.none?{|m| m == method }
|
113
|
+
end
|
114
|
+
#------------------------------------------------------------------------
|
115
|
+
def self.prefix
|
116
|
+
"https://ruby-doc.org/core-2.4.3/"
|
117
|
+
end
|
118
|
+
|
119
|
+
def self.expand
|
120
|
+
"\nTo View Full Documentation Enter 'expand'".yellow
|
121
|
+
end
|
122
|
+
#========================================================================
|
123
|
+
def self.changelog
|
124
|
+
html = Nokogiri::HTML(open("https://github.com/AlphaDaniel/ruby_doc/blob/master/changelog.md"))
|
125
|
+
|
126
|
+
puts html.search("#readme").text.gsub("\n ", "").gsub("\n\n\n ", "")
|
127
|
+
end
|
128
|
+
|
129
|
+
def self.coming_soon
|
130
|
+
html = Nokogiri::HTML(open("https://github.com/AlphaDaniel/ruby_doc"))
|
131
|
+
|
132
|
+
list = ""
|
133
|
+
html.search("div#readme ul li").each do |li|
|
134
|
+
list << ">> ".cyan + li.text + "\n"
|
135
|
+
end
|
136
|
+
list
|
137
|
+
end
|
138
|
+
#========================================================================
|
139
|
+
end
|
data/lib/ruby_doc/version.rb
CHANGED
data/ruby_doc.gemspec
CHANGED
@@ -10,8 +10,8 @@ Gem::Specification.new do |spec|
|
|
10
10
|
spec.email = ["daniel.nunez.nyc@gmail.com"]
|
11
11
|
|
12
12
|
spec.summary = %q{A CLI Gem that scrapes Ruby documentation.}
|
13
|
-
spec.description = %q{Ever get tired of leaving your editor/environment to google a method, or more in depth info on a class or module?
|
14
|
-
spec.homepage = "https://github.com/AlphaDaniel/
|
13
|
+
spec.description = %q{Ever get tired of leaving your editor/environment to google a method, or more in depth info on a class or module? \nThis gem aims to make Ruby referencing quick and more importantly, LOCAL. \n\nRuby Doc scrapes Ruby documentation and allows users to quickly reference Ruby Language methods and additional information all on your terminal. Have a query? run, hunt, and done. Never lose momentum, keep all things in your line of sight and get right back to coding. Enjoy.}
|
14
|
+
spec.homepage = "https://github.com/AlphaDaniel/ruby_doc"
|
15
15
|
spec.license = "MIT"
|
16
16
|
|
17
17
|
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ruby_doc
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 2.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Daniel Nunez
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-02-
|
11
|
+
date: 2018-02-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -107,8 +107,8 @@ dependencies:
|
|
107
107
|
- !ruby/object:Gem::Version
|
108
108
|
version: 1.8.1
|
109
109
|
description: Ever get tired of leaving your editor/environment to google a method,
|
110
|
-
or more in depth info on a class or module?
|
111
|
-
quick and more importantly, LOCAL.
|
110
|
+
or more in depth info on a class or module? \nThis gem aims to make Ruby referencing
|
111
|
+
quick and more importantly, LOCAL. \n\nRuby Doc scrapes Ruby documentation and allows
|
112
112
|
users to quickly reference Ruby Language methods and additional information all
|
113
113
|
on your terminal. Have a query? run, hunt, and done. Never lose momentum, keep all
|
114
114
|
things in your line of sight and get right back to coding. Enjoy.
|
@@ -124,7 +124,6 @@ files:
|
|
124
124
|
- Gemfile
|
125
125
|
- Gemfile.lock
|
126
126
|
- LICENSE.txt
|
127
|
-
- Notes.md
|
128
127
|
- README.md
|
129
128
|
- Rakefile
|
130
129
|
- bin/console
|
@@ -132,16 +131,16 @@ files:
|
|
132
131
|
- bin/setup
|
133
132
|
- changelog.md
|
134
133
|
- config/environment.rb
|
135
|
-
-
|
136
|
-
- lib/ruby_doc/
|
137
|
-
- lib/ruby_doc/
|
138
|
-
- lib/ruby_doc/data/
|
139
|
-
- lib/ruby_doc/
|
140
|
-
- lib/ruby_doc/
|
141
|
-
- lib/ruby_doc/
|
134
|
+
- config/patches.rb
|
135
|
+
- lib/ruby_doc/cli/cli.rb
|
136
|
+
- lib/ruby_doc/cli/ui.rb
|
137
|
+
- lib/ruby_doc/data/class.rb
|
138
|
+
- lib/ruby_doc/data/data_processor.rb
|
139
|
+
- lib/ruby_doc/data/method.rb
|
140
|
+
- lib/ruby_doc/data/scraper.rb
|
142
141
|
- lib/ruby_doc/version.rb
|
143
142
|
- ruby_doc.gemspec
|
144
|
-
homepage: https://github.com/AlphaDaniel/
|
143
|
+
homepage: https://github.com/AlphaDaniel/ruby_doc
|
145
144
|
licenses:
|
146
145
|
- MIT
|
147
146
|
metadata: {}
|
data/Notes.md
DELETED
@@ -1,37 +0,0 @@
|
|
1
|
-
# NOTES:
|
2
|
-
|
3
|
-
### SEARCH BY METHOD FEATURE:
|
4
|
-
For now the search feature only searches all doc objects (iterating Doc.all)
|
5
|
-
I would like to improve this to also search through all Meth objects.
|
6
|
-
The issue here explained below...
|
7
|
-
|
8
|
-
Population of all methods can only be done through scraping each individual
|
9
|
-
doc page for all its meth urls. In this site, methods are spread out
|
10
|
-
and not available in their entirety, in a singular container or list.
|
11
|
-
|
12
|
-
Roadmap: In this CLI I pre-load all docs through Scraper.loadDOCS in
|
13
|
-
environment.rb before my exec is ran. When user first lands at UI.greeting
|
14
|
-
all docs (objects) are already loaded.
|
15
|
-
|
16
|
-
To initiate the scrape I need to retrieve a method for instantiation,
|
17
|
-
I pass in a Doc class object's url attribute. Since, as previously stated,
|
18
|
-
ALL methods do not live in one place... The logical solution would be to
|
19
|
-
iterate through Doc.all, pass (obj).url to block and call Scraper.load_doc_page()
|
20
|
-
passing in every iteration. This would essentially instantiate meth objects
|
21
|
-
for all methods included on all doc pages.
|
22
|
-
|
23
|
-
2 big issues arise with this fact. The first and most important URI will not
|
24
|
-
let me iterate and open each page (redirection open loop error). 2nd,
|
25
|
-
even if we did we would be opening, scraping, and iterating through
|
26
|
-
2403 different site pages. As you can imagine this would not be practical
|
27
|
-
|
28
|
-
Plan for improvement:
|
29
|
-
I will be researching a way to patch this error so as to allow the iteration
|
30
|
-
and if successful decide on implementation based on run time.
|
31
|
-
|
32
|
-
If unsuccessful I will be looking into changing my scrapers to point to
|
33
|
-
http://ruby-doc.org/ which was my initial plan with this CLI. As this is
|
34
|
-
my very first CLI the layout of this site was a bit intimidating at first glance
|
35
|
-
as far as scraping successfully. At the completetion of this CLI I am now
|
36
|
-
a lot more confident in my abilities so this will most likely be the way
|
37
|
-
I go.
|
@@ -1,151 +0,0 @@
|
|
1
|
-
module DataExtras # = foreign method
|
2
|
-
#=====================================================================
|
3
|
-
#HELPERS
|
4
|
-
#=====================================================================
|
5
|
-
#@all set/get maker for Doc & Meth
|
6
|
-
def self.extended(base)
|
7
|
-
base.class_variable_set(:@@all, [])
|
8
|
-
end
|
9
|
-
|
10
|
-
def all
|
11
|
-
self.class_variable_get(:@@all)
|
12
|
-
end
|
13
|
-
|
14
|
-
#UIExtras Shuttles
|
15
|
-
def self.uie
|
16
|
-
RubyDoc::CLI::UI
|
17
|
-
end
|
18
|
-
|
19
|
-
def uie
|
20
|
-
RubyDoc::CLI::UI
|
21
|
-
end
|
22
|
-
#=====================================================================
|
23
|
-
#PAGINATOR
|
24
|
-
#=====================================================================
|
25
|
-
#PageLister
|
26
|
-
def list(page)
|
27
|
-
page.each_with_index{|doc, index| uie.outputD(doc, index)}
|
28
|
-
end
|
29
|
-
|
30
|
-
def self.list(page)
|
31
|
-
page.each_with_index{|doc, index| uie.outputD(doc, index)}
|
32
|
-
end
|
33
|
-
|
34
|
-
#PageShuttle
|
35
|
-
def self.nextPage(currentPg)
|
36
|
-
case currentPg
|
37
|
-
when "Page1"
|
38
|
-
page2
|
39
|
-
when "Page2"
|
40
|
-
page3
|
41
|
-
when "Page3"
|
42
|
-
page4
|
43
|
-
when "Page4"
|
44
|
-
last
|
45
|
-
end
|
46
|
-
end
|
47
|
-
#==============================PaginateAll============================
|
48
|
-
def paginateALL
|
49
|
-
uie.sepL#
|
50
|
-
list(Doc.all[0..499])#
|
51
|
-
puts uie.sepR#
|
52
|
-
|
53
|
-
uie.browseMenu#
|
54
|
-
uie.browseControl("Page1", Doc.all[0..499])#
|
55
|
-
end
|
56
|
-
#================================Page 2===============================
|
57
|
-
def self.page2
|
58
|
-
uie.sepL#
|
59
|
-
list(Doc.all[500..999])#
|
60
|
-
puts uie.sepR#
|
61
|
-
|
62
|
-
uie.browseMenu#
|
63
|
-
uie.browseControl("Page2", Doc.all[500..999])#
|
64
|
-
end
|
65
|
-
#================================Page 3===============================
|
66
|
-
def self.page3
|
67
|
-
uie.sepL#
|
68
|
-
list(Doc.all[1000..1499])#
|
69
|
-
puts uie.sepR#
|
70
|
-
|
71
|
-
uie.browseMenu#
|
72
|
-
uie.browseControl("Page3", Doc.all[1000..1499])#
|
73
|
-
end
|
74
|
-
#================================Page 4===============================
|
75
|
-
def self.page4
|
76
|
-
uie.sepL#
|
77
|
-
list(Doc.all[1500..1999])#
|
78
|
-
puts uie.sepR#
|
79
|
-
|
80
|
-
uie.browseMenu#
|
81
|
-
uie.browseControl("Page4", Doc.all[1500..1999])#
|
82
|
-
end
|
83
|
-
#===============================Page Last=============================
|
84
|
-
def self.last
|
85
|
-
uie.sepL#
|
86
|
-
list(Doc.all[2000..Doc.all.length])#
|
87
|
-
puts uie.sepR#
|
88
|
-
|
89
|
-
uie.viewMenu#
|
90
|
-
uie.browseControl("Last", Doc.all[2000..Doc.all.length])#
|
91
|
-
end
|
92
|
-
#==============================Display Doc============================
|
93
|
-
def display(doc)
|
94
|
-
Scraper.loadDocPage(doc)#Load
|
95
|
-
|
96
|
-
uie.sepL#
|
97
|
-
puts "Title: ".cyan + doc.name.upcase
|
98
|
-
puts "Type: ".cyan + doc.type.upcase
|
99
|
-
puts "\nDescription:".cyan
|
100
|
-
description = doc.description
|
101
|
-
puts uie.wrapped(description, 55)
|
102
|
-
puts "\nMethods: ".cyan + "#{doc.methods.count}".yellow
|
103
|
-
puts "Source: #{doc.url}".red
|
104
|
-
puts uie.sepR#
|
105
|
-
|
106
|
-
uie.docMenu(doc)#
|
107
|
-
uie.docControl(doc)#
|
108
|
-
end
|
109
|
-
#==============================List Meths=============================
|
110
|
-
def listMeths(doc)
|
111
|
-
uie.sepL#
|
112
|
-
doc.methods.each_with_index do |meth, index|
|
113
|
-
puts "#{index + 1}. ".yellow + meth.cyan
|
114
|
-
end
|
115
|
-
puts uie.sepR#
|
116
|
-
|
117
|
-
uie.viewMenu#
|
118
|
-
uie.methListControl(doc)#
|
119
|
-
end
|
120
|
-
#=============================Display Meth============================
|
121
|
-
def displayMeth(byName)
|
122
|
-
meth = Meth.find(byName)
|
123
|
-
Scraper.loadMethPage(meth)#Load
|
124
|
-
|
125
|
-
uie.sepL#
|
126
|
-
puts "Title: ".cyan + meth.name.upcase
|
127
|
-
puts "Type: ".cyan + meth.type.upcase
|
128
|
-
puts "\nDescription:".cyan
|
129
|
-
description = meth.description
|
130
|
-
puts uie.wrapped(description, 55)
|
131
|
-
puts "\nSource: #{meth.url}".red
|
132
|
-
puts uie.sepR#
|
133
|
-
|
134
|
-
uie.methMenu#
|
135
|
-
uie.methControl#
|
136
|
-
|
137
|
-
RubyDoc::CLI.start if iN == "m"
|
138
|
-
end
|
139
|
-
#=============================SUPER SEARCH============================
|
140
|
-
def superSEARCH(name)
|
141
|
-
uie.sepL#
|
142
|
-
matches = Doc.all.find_all{|doc| doc.name.downcase.include?(name)}
|
143
|
-
|
144
|
-
uie.searchControl(matches)#
|
145
|
-
puts uie.sepR#
|
146
|
-
|
147
|
-
uie.viewMenu#
|
148
|
-
uie.choiceControl(matches)#
|
149
|
-
end
|
150
|
-
#=====================================================================
|
151
|
-
end
|