ruby_dictionary 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +11 -0
- data/.rspec +3 -0
- data/.travis.yml +5 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +6 -0
- data/Gemfile.lock +45 -0
- data/LICENSE.txt +21 -0
- data/NOTES.md +39 -0
- data/README.md +44 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/ruby-dictionary +8 -0
- data/bin/setup +8 -0
- data/lib/ruby_dictionary/cli.rb +119 -0
- data/lib/ruby_dictionary/findable.rb +7 -0
- data/lib/ruby_dictionary/klass.rb +64 -0
- data/lib/ruby_dictionary/method.rb +28 -0
- data/lib/ruby_dictionary/scraper.rb +100 -0
- data/lib/ruby_dictionary/version.rb +3 -0
- data/lib/ruby_dictionary.rb +11 -0
- data/ruby_dictionary.gemspec +39 -0
- data/spec.md +9 -0
- data/tring_methods +26 -0
- metadata +138 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 38ecfaba82284e4a4ce77623fd1e47669c2721a7
|
4
|
+
data.tar.gz: f238b5e29403e852e937896ead724ee49a195e92
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: b8d4edcda9073f65e951913d4ff9410065a830dbd565f04e6018a4151869bee7e6b03dec6a7e2addb2a6dbd7b395858db3e129559fd848e4d31dc868b0ee0316
|
7
|
+
data.tar.gz: 158cf03a06539b2f39019ef304d5a557aff2831e01bf882e854e5c3c4ec2faec213973358b1e0f92cb489558cac736ed59d996c38ad59fdace7fbb72af18f65f
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -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 <github email address>. 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
data/Gemfile.lock
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
ruby_dictionary (0.1.0)
|
5
|
+
nokogiri
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: https://rubygems.org/
|
9
|
+
specs:
|
10
|
+
coderay (1.1.2)
|
11
|
+
diff-lcs (1.3)
|
12
|
+
method_source (0.9.0)
|
13
|
+
mini_portile2 (2.3.0)
|
14
|
+
nokogiri (1.8.1)
|
15
|
+
mini_portile2 (~> 2.3.0)
|
16
|
+
pry (0.11.3)
|
17
|
+
coderay (~> 1.1.0)
|
18
|
+
method_source (~> 0.9.0)
|
19
|
+
rake (10.5.0)
|
20
|
+
rspec (3.7.0)
|
21
|
+
rspec-core (~> 3.7.0)
|
22
|
+
rspec-expectations (~> 3.7.0)
|
23
|
+
rspec-mocks (~> 3.7.0)
|
24
|
+
rspec-core (3.7.0)
|
25
|
+
rspec-support (~> 3.7.0)
|
26
|
+
rspec-expectations (3.7.0)
|
27
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
28
|
+
rspec-support (~> 3.7.0)
|
29
|
+
rspec-mocks (3.7.0)
|
30
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
31
|
+
rspec-support (~> 3.7.0)
|
32
|
+
rspec-support (3.7.0)
|
33
|
+
|
34
|
+
PLATFORMS
|
35
|
+
ruby
|
36
|
+
|
37
|
+
DEPENDENCIES
|
38
|
+
bundler (~> 1.16)
|
39
|
+
pry
|
40
|
+
rake (~> 10.0)
|
41
|
+
rspec (~> 3.0)
|
42
|
+
ruby_dictionary!
|
43
|
+
|
44
|
+
BUNDLED WITH
|
45
|
+
1.16.0
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2017 TODO: Write your name
|
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.
|
data/NOTES.md
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
Building a CLI gem
|
2
|
+
|
3
|
+
1. Plan out, imagine UI
|
4
|
+
2. Build out project structure
|
5
|
+
3. Start with the file run, shebang line, and relative requirements
|
6
|
+
4. stub out the interface
|
7
|
+
5. Start making things real
|
8
|
+
6. Discover objects
|
9
|
+
7. Program
|
10
|
+
|
11
|
+
|
12
|
+
A command line interface that allows a user to browse Public instance methods for different data types.
|
13
|
+
|
14
|
+
user types ruby-dictionary
|
15
|
+
|
16
|
+
Welcomes the user
|
17
|
+
asks what Class/Mixin the user wants to explore
|
18
|
+
prompts for input
|
19
|
+
Displays definition of Class
|
20
|
+
asks user if they want to display instance methods or class methods
|
21
|
+
lists public instance/class/all methods for the selected data type
|
22
|
+
|
23
|
+
Which method do you want to learn more about?
|
24
|
+
prompts user to enter #method
|
25
|
+
returns description and examples
|
26
|
+
|
27
|
+
|
28
|
+
I think I should create separate Scraper and Method classes
|
29
|
+
|
30
|
+
FINDABLE?
|
31
|
+
|
32
|
+
FIND OUT HOW TO REMOVE HTML TAGS FROM DESCRIPTIONS (ie See Also links)
|
33
|
+
|
34
|
+
IS THERE A WAY TO SET UP AN ANCHOR IN MY CLI MENU SO THAT WHEN I TYPE EXIT FROM A KLASS MENU IT EXITS THE CLI MENU AND SKIPS TO #GOODBY?
|
35
|
+
|
36
|
+
ADJUST/ADD CLEAR ALL METHOD?
|
37
|
+
|
38
|
+
|
39
|
+
NEED TO ADD A CONDITION THAT METHODS SHOULD ONLY BE ADDED TO ALL/INST_METHODS/KLASS_METHODS IF THAT METHOD CANNOT BE FOUND IN THERE.
|
data/README.md
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
# RubyDictionary
|
2
|
+
|
3
|
+
Welcome to the Ruby Dictionary gem. With this gem you will be able to do more than just print a list of methods that can be called on an object. This gem allows you to view methods available to you, and call up a description of each method along with available call sequences and examples scraped straight from ruby-docs.
|
4
|
+
|
5
|
+
This gem is powered by the Core API docs for Ruby 2.4.2 found at:
|
6
|
+
http://ruby-doc.org/
|
7
|
+
|
8
|
+
## Installation
|
9
|
+
|
10
|
+
Add this line to your application's Gemfile:
|
11
|
+
|
12
|
+
```ruby
|
13
|
+
gem 'ruby_dictionary'
|
14
|
+
```
|
15
|
+
|
16
|
+
And then execute:
|
17
|
+
|
18
|
+
$ bundle
|
19
|
+
|
20
|
+
Or install it yourself as:
|
21
|
+
|
22
|
+
$ gem install ruby_dictionary
|
23
|
+
|
24
|
+
## Usage
|
25
|
+
|
26
|
+
The program opens with a list of ruby classes and mixins. you can navigate to any of the class menus by entering the name or associated number into the command line. From there, follow the simple instructions provided in each menu to navigate through this program and you will have access to the power of the official Ruby core 2.4.2 API docs right from your command line.
|
27
|
+
|
28
|
+
## Development
|
29
|
+
|
30
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
31
|
+
|
32
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
33
|
+
|
34
|
+
## Contributing
|
35
|
+
|
36
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/<github username>/ruby_dictionary. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
37
|
+
|
38
|
+
## License
|
39
|
+
|
40
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
41
|
+
|
42
|
+
## Code of Conduct
|
43
|
+
|
44
|
+
Everyone interacting in the RubyDictionary project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/<github username>/ruby_dictionary/blob/master/CODE_OF_CONDUCT.md).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "ruby_dictionary"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start(__FILE__)
|
data/bin/ruby-dictionary
ADDED
data/bin/setup
ADDED
@@ -0,0 +1,119 @@
|
|
1
|
+
# CLI Controller
|
2
|
+
require 'pry'
|
3
|
+
class CLI
|
4
|
+
|
5
|
+
def call
|
6
|
+
Scraper.scrape_index
|
7
|
+
puts "Welcome to the Ruby Dictionary!"
|
8
|
+
scrape_slow_classes
|
9
|
+
list_klasses
|
10
|
+
main_menu
|
11
|
+
goodbye
|
12
|
+
end
|
13
|
+
|
14
|
+
def scrape_slow_classes
|
15
|
+
@array = Klass.list[0]
|
16
|
+
Scraper.scrape_klass(@array)
|
17
|
+
@enum = Klass.list[2]
|
18
|
+
Scraper.scrape_klass(@enum)
|
19
|
+
end
|
20
|
+
|
21
|
+
def list_klasses
|
22
|
+
Klass.all.each.with_index{|k,i| puts "#{i + 1}. #{k.name}"}
|
23
|
+
puts "\nEnter the Class or Mixin you would like to explore, or type 'exit' to quit"
|
24
|
+
end
|
25
|
+
|
26
|
+
def klass_menu(klass)
|
27
|
+
input = nil
|
28
|
+
puts "\n"
|
29
|
+
puts klass.definition
|
30
|
+
puts "\nEnter 'i' to see a list of public instance methods\nEnter 'c' to see a list of public class methods\nEnter 'all' to see all public methods available\nEnter the name of a method to learn more\nEnter 'menu' or 'back' to go back to the list of Classes and Mixins\nOr enter 'exit' to quit"
|
31
|
+
until input == "menu" || input == "back"
|
32
|
+
input = gets.strip.downcase
|
33
|
+
case
|
34
|
+
when input == "i" || input == "instance"
|
35
|
+
klass.list_inst_methods
|
36
|
+
puts "\n"
|
37
|
+
when input == "c" || input == "class"
|
38
|
+
klass.list_klass_methods
|
39
|
+
puts "\n"
|
40
|
+
when input == "all"
|
41
|
+
klass.list_all_methods
|
42
|
+
puts "\n"
|
43
|
+
when input == "menu" || input == "back"
|
44
|
+
list_klasses
|
45
|
+
when input == "exit"
|
46
|
+
puts "Happy Coding!!!"
|
47
|
+
exit
|
48
|
+
else
|
49
|
+
if klass.find_by_name(input) == nil
|
50
|
+
puts "Im sorry, I can't find a method by that name, try again or type 'menu' to go to the main menu or type 'exit' to quit"
|
51
|
+
else
|
52
|
+
method = klass.find_by_name(input)
|
53
|
+
puts "\n##{method.name}\n"
|
54
|
+
method.callseq.each do |seq|
|
55
|
+
puts seq
|
56
|
+
end
|
57
|
+
puts "\n#{method.description}"
|
58
|
+
if method.examples != ""
|
59
|
+
puts "\nExamples:\n#{method.examples}\n"
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
def main_menu
|
67
|
+
input = nil
|
68
|
+
until input == "exit"
|
69
|
+
|
70
|
+
input = gets.strip.downcase
|
71
|
+
case input
|
72
|
+
when "list"
|
73
|
+
list_klasses
|
74
|
+
when /array(s)?\b|1/
|
75
|
+
klass_menu(@array)
|
76
|
+
when /dir(s)?\b|2/
|
77
|
+
@dir = Klass.list[1]
|
78
|
+
Scraper.scrape_klass(@dir)
|
79
|
+
klass_menu(@dir)
|
80
|
+
when /enumerable(s)?\b|3/
|
81
|
+
klass_menu(@enum)
|
82
|
+
when /hash(es)?\b|4/
|
83
|
+
@hash = Klass.list[3]
|
84
|
+
Scraper.scrape_klass(@hash)
|
85
|
+
klass_menu(@hash)
|
86
|
+
when /numeric(s)?\b|5/
|
87
|
+
@num = Klass.list[4]
|
88
|
+
Scraper.scrape_klass(@num)
|
89
|
+
klass_menu(@num)
|
90
|
+
when /proc(s)?\b|6/
|
91
|
+
@prok = Klass.list[5]
|
92
|
+
Scraper.scrape_klass(@prok)
|
93
|
+
klass_menu(@prok)
|
94
|
+
when /range(s)?\b|7/
|
95
|
+
@range = Klass.list[6]
|
96
|
+
Scraper.scrape_klass(@range)
|
97
|
+
klass_menu(@range)
|
98
|
+
when /string(s)?\b|8/
|
99
|
+
@string = Klass.list[7]
|
100
|
+
Scraper.scrape_klass(@string)
|
101
|
+
klass_menu(@string)
|
102
|
+
when /symbol(s)?\b|9/
|
103
|
+
@symbol = Klass.list[8]
|
104
|
+
Scraper.scrape_klass(@symbol)
|
105
|
+
klass_menu(@symbol)
|
106
|
+
else
|
107
|
+
if input != "exit"
|
108
|
+
puts "I'm sorry, I didn't get that. Please enter a Class or type 'list' or type 'exit'"
|
109
|
+
end
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
|
114
|
+
def goodbye
|
115
|
+
puts "Happy Coding!!!"
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
119
|
+
end
|
@@ -0,0 +1,64 @@
|
|
1
|
+
class Klass
|
2
|
+
include Findable::InstanceMethods
|
3
|
+
attr_accessor :name, :definition, :url, :method
|
4
|
+
@@all = []
|
5
|
+
|
6
|
+
def initialize(name=nil,definition=nil,url=nil)
|
7
|
+
@name = name
|
8
|
+
@definition = definition
|
9
|
+
@url = url
|
10
|
+
@klass_methods = []
|
11
|
+
@inst_methods = []
|
12
|
+
@all_methods = []
|
13
|
+
end
|
14
|
+
|
15
|
+
def add_inst_method(method)
|
16
|
+
method.klass = self unless method.klass != nil
|
17
|
+
@inst_methods << method unless @inst_methods.include?(method)
|
18
|
+
end
|
19
|
+
|
20
|
+
def add_klass_method(method)
|
21
|
+
method.klass = self unless method.klass != nil
|
22
|
+
@klass_methods << method unless @klass_methods.include?(method)
|
23
|
+
end
|
24
|
+
|
25
|
+
def self.all
|
26
|
+
@@all
|
27
|
+
end
|
28
|
+
|
29
|
+
def self.list
|
30
|
+
@@all.each{|k| k.name}
|
31
|
+
end
|
32
|
+
|
33
|
+
def inst_methods
|
34
|
+
@inst_methods
|
35
|
+
end
|
36
|
+
|
37
|
+
def klass_methods
|
38
|
+
@klass_methods
|
39
|
+
end
|
40
|
+
|
41
|
+
def all_methods
|
42
|
+
@all_methods
|
43
|
+
end
|
44
|
+
|
45
|
+
def list_inst_methods
|
46
|
+
@all_methods.each{|m| puts m.name if m.method_type == "Instance"}
|
47
|
+
end
|
48
|
+
|
49
|
+
def list_klass_methods
|
50
|
+
@all_methods.each{|m| puts m.name if m.method_type == "Class"}
|
51
|
+
end
|
52
|
+
|
53
|
+
def list_all_methods
|
54
|
+
@all_methods.each{|m| puts m.name}
|
55
|
+
end
|
56
|
+
|
57
|
+
def clear_method_lists
|
58
|
+
@inst_methods.clear
|
59
|
+
@klass_methods.clear
|
60
|
+
@all_methods.clear
|
61
|
+
end
|
62
|
+
|
63
|
+
|
64
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
class RubyMethod
|
2
|
+
include Findable::InstanceMethods
|
3
|
+
attr_accessor :name, :callseq, :description, :examples, :method_type, :klass
|
4
|
+
@@all = []
|
5
|
+
|
6
|
+
def initialize(name=nil,callseq=nil,description=nil,examples=nil,method_type=nil, klass_name=nil, klass=nil)
|
7
|
+
@name = name
|
8
|
+
@callseq = callseq
|
9
|
+
@description = description
|
10
|
+
@examples = examples
|
11
|
+
@method_type = method_type
|
12
|
+
@klass_name = klass_name
|
13
|
+
@klass = klass
|
14
|
+
#self.klass=(klass_name) unless klass_name == nil
|
15
|
+
|
16
|
+
end
|
17
|
+
|
18
|
+
# def klass=(klass)
|
19
|
+
# binding.pry
|
20
|
+
# @klass = klass
|
21
|
+
# if self.method_type == "Class"
|
22
|
+
# klass.add_klass_method(self)
|
23
|
+
# else
|
24
|
+
# klass.add_inst_method(self)
|
25
|
+
# end
|
26
|
+
# end
|
27
|
+
|
28
|
+
end
|
@@ -0,0 +1,100 @@
|
|
1
|
+
require 'nokogiri'
|
2
|
+
require 'uri'
|
3
|
+
require 'pry'
|
4
|
+
|
5
|
+
class Scraper
|
6
|
+
|
7
|
+
def self.scrape_index
|
8
|
+
doc = Nokogiri::HTML(open("http://ruby-doc.org/core-2.4.2/"))
|
9
|
+
klass_list = doc.css("#class-index .entries p")
|
10
|
+
klass_list.each do |k|
|
11
|
+
if k.css("a").text.match(/(Array\b|Dir\b|Enumerable|Hash|Numeric|Proc\b|Range\b|String|Symbol)/) != nil
|
12
|
+
klass = Klass.new
|
13
|
+
klass.name = k.css("a").text.gsub(/"/,"")
|
14
|
+
href = k.css("a")[0]["href"]
|
15
|
+
page_url = "http://ruby-doc.org/core-2.4.2/"
|
16
|
+
klass.url = URI.join(page_url,href)
|
17
|
+
Klass.all << klass
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def self.scrape_klass(klass)
|
23
|
+
self.scrape_method_names(klass)
|
24
|
+
self.scrape_instance_method_bodies(klass)
|
25
|
+
self.scrape_klass_method_bodies(klass)
|
26
|
+
end
|
27
|
+
|
28
|
+
def self.scrape_method_names(klass)
|
29
|
+
doc = Nokogiri::HTML(open(klass.url))
|
30
|
+
klass.definition = doc.css("div#description p:first-child, div#description p:nth-child(2)").text
|
31
|
+
#.gsub(/<span.{1,25}>|<\/span>/,"").gsub(/<code>|<\/code>/,"").gsub(/<|>|&/, '<' => "<", '>' => ">", '&' => "&")
|
32
|
+
method_list = doc.css("#method-list-section ul.link-list li")
|
33
|
+
|
34
|
+
method_list.each do |mn|
|
35
|
+
method = RubyMethod.new
|
36
|
+
if mn.css("a").text.start_with?(":")
|
37
|
+
method.method_type = "Class"
|
38
|
+
klass.add_klass_method(method)
|
39
|
+
else
|
40
|
+
method.method_type = "Instance"
|
41
|
+
klass.add_inst_method(method)
|
42
|
+
end
|
43
|
+
method.klass = klass
|
44
|
+
method.name = mn.css("a").text.gsub(/#/,"")
|
45
|
+
#.gsub(/<|>|&|#/, '<' => "<", '>' => ">", '&' => "&", '#' => "")
|
46
|
+
klass.all_methods << method
|
47
|
+
end
|
48
|
+
end
|
49
|
+
####################################################################################
|
50
|
+
def self.scrape_instance_method_bodies(klass)
|
51
|
+
doc = Nokogiri::HTML(open(klass.url))
|
52
|
+
i=0
|
53
|
+
#if method.method_type == "Instance"
|
54
|
+
public_instance_methods = doc.css("div#public-instance-method-details.method-section .method-detail")
|
55
|
+
public_instance_methods.each do |m|
|
56
|
+
|
57
|
+
klass.inst_methods[i].description = m.css(".method-heading + div p").text
|
58
|
+
#.gsub(/<.{2,5}>|\n/,"").strip.gsub(/<|>|&/, '<' => "<", '>' =>">", '&' => "&")
|
59
|
+
klass.inst_methods[i].examples = m.css("pre.ruby").text
|
60
|
+
#.gsub(/<span class=\"ruby-.{1,12}>|<\/span>/,"").strip.gsub(/<|>|&/, '<' => "<", '>' => ">", '&' => "&")
|
61
|
+
|
62
|
+
call_sequence = []
|
63
|
+
if m.css(".method-heading").length == 1
|
64
|
+
call_sequence << m.css(".method-callseq").text
|
65
|
+
#.gsub(/<|>|&/, '<' => "<",'>' => ">", '&' => "&")
|
66
|
+
else
|
67
|
+
m.css(".method-heading").each do |variant|
|
68
|
+
call_sequence << variant.css(".method-callseq").text
|
69
|
+
end
|
70
|
+
end
|
71
|
+
klass.inst_methods[i].callseq = call_sequence
|
72
|
+
i+=1
|
73
|
+
end
|
74
|
+
|
75
|
+
end
|
76
|
+
|
77
|
+
def self.scrape_klass_method_bodies(klass)
|
78
|
+
doc = Nokogiri::HTML(open(klass.url))
|
79
|
+
public_klass_methods = doc.css("div#public-class-method-details.method-section .method-detail")
|
80
|
+
i=0
|
81
|
+
public_klass_methods.each do |m|
|
82
|
+
|
83
|
+
klass.klass_methods[i].description = m.css(".method-heading + div p").text
|
84
|
+
#.gsub(/<.{2,5}>|\n/,"").strip.gsub(/<|>|&/, '<' => "<", '>' =>">", '&' => "&")
|
85
|
+
klass.klass_methods[i].examples = m.css("pre.ruby").text.strip
|
86
|
+
#.gsub(/<span class=\"ruby-.{1,12}>|<\/span>/,"").strip.gsub(/<|>|&/, '<' => "<", '>' => ">", '&' => "&")
|
87
|
+
call_sequence = []
|
88
|
+
if m.css(".method-heading").length == 1
|
89
|
+
call_sequence << m.css(".method-callseq").text
|
90
|
+
#.gsub(/<|>|&/, '<' => "<",'>' => ">", '&' => "&")
|
91
|
+
else
|
92
|
+
m.css(".method-heading").each do |variant|
|
93
|
+
call_sequence << variant.css(".method-callseq").text
|
94
|
+
end
|
95
|
+
end
|
96
|
+
klass.klass_methods[i].callseq = call_sequence
|
97
|
+
i+=1
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
require 'nokogiri'
|
2
|
+
require 'open-uri'
|
3
|
+
require 'pry'
|
4
|
+
|
5
|
+
require_relative './ruby_dictionary/findable'
|
6
|
+
|
7
|
+
require_relative "./ruby_dictionary/version"
|
8
|
+
require_relative './ruby_dictionary/cli'
|
9
|
+
require_relative './ruby_dictionary/method'
|
10
|
+
require_relative './ruby_dictionary/klass'
|
11
|
+
require_relative './ruby_dictionary/scraper'
|
@@ -0,0 +1,39 @@
|
|
1
|
+
|
2
|
+
lib = File.expand_path("../lib", __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require "ruby_dictionary/version"
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "ruby_dictionary"
|
8
|
+
spec.version = RubyDictionary::VERSION
|
9
|
+
spec.authors = ["Chris Boujoukos"]
|
10
|
+
spec.email = ["cboujoukos@gmail.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{Ruby Dictionary}
|
13
|
+
spec.description = %q{This gem allows the user to look up useful information on public methods right from the command line.}
|
14
|
+
spec.homepage = "https://github.com/cboujoukos/cli-data-gem-assessment-v-000.git"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
# Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
|
18
|
+
# to allow pushing to a single host or delete this section to allow pushing to any host.
|
19
|
+
# if spec.respond_to?(:metadata)
|
20
|
+
# spec.metadata["allowed_push_host"] = "Set to 'http://mygemserver.com'"
|
21
|
+
# else
|
22
|
+
# raise "RubyGems 2.0 or newer is required to protect against " \
|
23
|
+
# "public gem pushes."
|
24
|
+
# end
|
25
|
+
|
26
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
27
|
+
f.match(%r{^(test|spec|features)/})
|
28
|
+
end
|
29
|
+
spec.bindir = "exe"
|
30
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
31
|
+
spec.require_paths = ["lib"]
|
32
|
+
|
33
|
+
spec.add_development_dependency "bundler", "~> 1.16"
|
34
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
35
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
36
|
+
spec.add_development_dependency "pry", "~>0"
|
37
|
+
|
38
|
+
spec.add_runtime_dependency "nokogiri"
|
39
|
+
end
|
data/spec.md
ADDED
@@ -0,0 +1,9 @@
|
|
1
|
+
# Specifications for the CLI Assessment
|
2
|
+
|
3
|
+
Specs:
|
4
|
+
- [x] Have a CLI for interfacing with the application
|
5
|
+
RubyDictionary::CLI class provides CLI for main menu and RubyDictionary::Klass class adds CLI functionality for detailed view
|
6
|
+
- [x] Pull data from an external source
|
7
|
+
RubyDictionary::Scraper class scrapes several pages of Ruby Documentation
|
8
|
+
- [x] Implement both list and detail views
|
9
|
+
Main menu allows navigation between different Ruby classes and a once a class is selected the user can find more information on any method (thanks to the Findable module).
|
data/tring_methods
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
|
2
|
+
[1mFrom:[0m /home/chris/code/portfolio-projects/ruby_dictionary/lib/ruby_dictionary/scraper.rb @ line 29 RubyDictionary::Klass.scrape_string:
|
3
|
+
|
4
|
+
[1;34m10[0m: [32mdef[0m [1;36mself[0m.[1;34mscrape_string[0m
|
5
|
+
[1;34m11[0m: string_methods = []
|
6
|
+
[1;34m12[0m: puts [31m[1;31m"[0m[31mWelcome to strings![1;31m"[0m[31m[0m
|
7
|
+
[1;34m13[0m: doc = [1;34;4mNokogiri[0m::HTML(open([31m[1;31m"[0m[31mhttp://ruby-doc.org/core-2.4.2/String.html[1;31m"[0m[31m[0m))
|
8
|
+
[1;34m14[0m: [1;34m#binding.pry[0m
|
9
|
+
[1;34m15[0m: instance_methods = doc.css([31m[1;31m"[0m[31m#public-instance-method-details .method-detail[1;31m"[0m[31m[0m)
|
10
|
+
[1;34m16[0m: [1;34m#binding.pry[0m
|
11
|
+
[1;34m17[0m:
|
12
|
+
[1;34m18[0m: instance_methods.each [32mdo[0m |m|
|
13
|
+
[1;34m19[0m: method = [1;36mself[0m.new
|
14
|
+
[1;34m20[0m: [1;34m#method.name = m.inner_html.split("→ ")[0] # This causes problems for methods that have multiple ways of of being called like slice(index), slice(range), slice(regexp), etc[0m
|
15
|
+
[1;34m21[0m: [32mif[0m m[[31m[1;31m"[0m[31mid[1;31m"[0m[31m[0m].split([31m[1;31m"[0m[31m-[1;31m"[0m[31m[0m)[[1;34m0[0m] == [35m[1;35m/[0m[35m^[1;35m\d[0m[35m.+[1;35m/[0m[35m[0m
|
16
|
+
[1;34m22[0m: method.name = m.inner_html.split([31m[1;31m"[0m[31m→ [1;31m"[0m[31m[0m)[[1;34m0[0m]
|
17
|
+
[1;34m23[0m: [32melse[0m
|
18
|
+
[1;34m24[0m: method.name = m[[31m[1;31m"[0m[31mid[1;31m"[0m[31m[0m].split([31m[1;31m"[0m[31m-[1;31m"[0m[31m[0m)[[1;34m0[0m] [1;34m#this causes problems methods that are stupidly classified as 2A 2A or 3D etc. (anything that comes before #bytes in the public method lists)[0m
|
19
|
+
[1;34m25[0m: [32mend[0m
|
20
|
+
[1;34m26[0m: string_methods << method
|
21
|
+
[1;34m27[0m: [32mend[0m
|
22
|
+
[1;34m28[0m: puts [31m[1;31m"[0m[31mwe scraped strings![1;31m"[0m[31m[0m
|
23
|
+
=> [1;34m29[0m: binding.pry
|
24
|
+
[1;34m30[0m:
|
25
|
+
[1;34m31[0m: [32mend[0m
|
26
|
+
|
metadata
ADDED
@@ -0,0 +1,138 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ruby_dictionary
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Chris Boujoukos
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-12-15 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: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: pry
|
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: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
description: This gem allows the user to look up useful information on public methods
|
84
|
+
right from the command line.
|
85
|
+
email:
|
86
|
+
- cboujoukos@gmail.com
|
87
|
+
executables: []
|
88
|
+
extensions: []
|
89
|
+
extra_rdoc_files: []
|
90
|
+
files:
|
91
|
+
- ".gitignore"
|
92
|
+
- ".rspec"
|
93
|
+
- ".travis.yml"
|
94
|
+
- CODE_OF_CONDUCT.md
|
95
|
+
- Gemfile
|
96
|
+
- Gemfile.lock
|
97
|
+
- LICENSE.txt
|
98
|
+
- NOTES.md
|
99
|
+
- README.md
|
100
|
+
- Rakefile
|
101
|
+
- bin/console
|
102
|
+
- bin/ruby-dictionary
|
103
|
+
- bin/setup
|
104
|
+
- lib/ruby_dictionary.rb
|
105
|
+
- lib/ruby_dictionary/cli.rb
|
106
|
+
- lib/ruby_dictionary/findable.rb
|
107
|
+
- lib/ruby_dictionary/klass.rb
|
108
|
+
- lib/ruby_dictionary/method.rb
|
109
|
+
- lib/ruby_dictionary/scraper.rb
|
110
|
+
- lib/ruby_dictionary/version.rb
|
111
|
+
- ruby_dictionary.gemspec
|
112
|
+
- spec.md
|
113
|
+
- tring_methods
|
114
|
+
homepage: https://github.com/cboujoukos/cli-data-gem-assessment-v-000.git
|
115
|
+
licenses:
|
116
|
+
- MIT
|
117
|
+
metadata: {}
|
118
|
+
post_install_message:
|
119
|
+
rdoc_options: []
|
120
|
+
require_paths:
|
121
|
+
- lib
|
122
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
123
|
+
requirements:
|
124
|
+
- - ">="
|
125
|
+
- !ruby/object:Gem::Version
|
126
|
+
version: '0'
|
127
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - ">="
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '0'
|
132
|
+
requirements: []
|
133
|
+
rubyforge_project:
|
134
|
+
rubygems_version: 2.6.7
|
135
|
+
signing_key:
|
136
|
+
specification_version: 4
|
137
|
+
summary: Ruby Dictionary
|
138
|
+
test_files: []
|