gem_menu 0.2.1
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 +7 -0
- data/.gitignore +11 -0
- data/.rspec +3 -0
- data/.travis.yml +7 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +6 -0
- data/Gemfile.lock +37 -0
- data/LICENSE.txt +21 -0
- data/README.md +43 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/demo/demo_environment.rb +3 -0
- data/demo/menu_demo.rb +28 -0
- data/demo/menus.rb +82 -0
- data/demo/methods.rb +43 -0
- data/gem_menu.gemspec +43 -0
- data/lib/gem_menu/version.rb +3 -0
- data/lib/gem_menu.rb +110 -0
- metadata +123 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: d346c0711ba4ef34c9ff357c59b36180c7ebf99a7132e0c0ecbec47d5f3172ad
|
4
|
+
data.tar.gz: b774e987187c5077ec14de74c7baf3793bd98f2faabf955d6dcc50ce963f9a06
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 0b406daedbb730f48b93acf8e2dcdd6512ea420682a3ee257aa59de4ce7e78f27e387a68903eab636a5e761ddbeb508d3bc3a93903733112387b1a8657186c15
|
7
|
+
data.tar.gz: 9a95165f4b937d625e995d682117d4b1abbd81e23dfc04fd57ba11f65086ba9dc7e767f7f0d2a43fd1213e7720be6750db1f9f27b4a720bf095c55ac7c90761f
|
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 brad.schrag@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
data/Gemfile.lock
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
gem_menu (0.1.0)
|
5
|
+
colorize (~> 0.8.1)
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: https://rubygems.org/
|
9
|
+
specs:
|
10
|
+
colorize (0.8.1)
|
11
|
+
diff-lcs (1.3)
|
12
|
+
rake (10.5.0)
|
13
|
+
rspec (3.8.0)
|
14
|
+
rspec-core (~> 3.8.0)
|
15
|
+
rspec-expectations (~> 3.8.0)
|
16
|
+
rspec-mocks (~> 3.8.0)
|
17
|
+
rspec-core (3.8.0)
|
18
|
+
rspec-support (~> 3.8.0)
|
19
|
+
rspec-expectations (3.8.2)
|
20
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
21
|
+
rspec-support (~> 3.8.0)
|
22
|
+
rspec-mocks (3.8.0)
|
23
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
24
|
+
rspec-support (~> 3.8.0)
|
25
|
+
rspec-support (3.8.0)
|
26
|
+
|
27
|
+
PLATFORMS
|
28
|
+
ruby
|
29
|
+
|
30
|
+
DEPENDENCIES
|
31
|
+
bundler (~> 1.17)
|
32
|
+
gem_menu!
|
33
|
+
rake (~> 10.0)
|
34
|
+
rspec (~> 3.0)
|
35
|
+
|
36
|
+
BUNDLED WITH
|
37
|
+
1.17.1
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2018 brad schrag
|
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/README.md
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
# GemMenu
|
2
|
+
|
3
|
+
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/gem_menu`. To experiment with that code, run `bin/console` for an interactive prompt.
|
4
|
+
|
5
|
+
TODO: Delete this and the text above, and describe your gem
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'gem_menu'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install gem_menu
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
TODO: Write usage instructions here
|
26
|
+
|
27
|
+
## Development
|
28
|
+
|
29
|
+
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.
|
30
|
+
|
31
|
+
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).
|
32
|
+
|
33
|
+
## Contributing
|
34
|
+
|
35
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/gem_menu. 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.
|
36
|
+
|
37
|
+
## License
|
38
|
+
|
39
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
40
|
+
|
41
|
+
## Code of Conduct
|
42
|
+
|
43
|
+
Everyone interacting in the GemMenu project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/gem_menu/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 "gem_menu"
|
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/setup
ADDED
data/demo/menu_demo.rb
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
require_relative "demo_environment"
|
2
|
+
|
3
|
+
# This is an example of a potential CLI interface using GemMenu. In the CLI,
|
4
|
+
# menus are created within methods. When these methods are called, they return
|
5
|
+
# their respective menus. Menus are created by first creating the Entry classes
|
6
|
+
# that populate the menu. Each Entry object has it's display text, a reference
|
7
|
+
# to it's next method or menu, and optionally parameters to be passed on.
|
8
|
+
|
9
|
+
# The Menu class is defined with the menu title text, an array of Entry objects,
|
10
|
+
# and optional arguments of previous_menu (should always be used except for the
|
11
|
+
# initial menu, unless using some other method to navigate backwards) and
|
12
|
+
# parameters. All menus will display with an (x) to exit and a (b) to go back,
|
13
|
+
# only if the menu was given a :previous_menu.
|
14
|
+
|
15
|
+
# To see how menus are created, check the menus.rb file, which has been required
|
16
|
+
|
17
|
+
# To see how the methods that are called should be construced, see the methods.rb
|
18
|
+
# file.
|
19
|
+
|
20
|
+
# Here we initiate our first menu, then loop setting menu equal to whatever is
|
21
|
+
# returned based on the user selection. This is why it's important that the
|
22
|
+
# methods within this file that are called from an Entry all return the menu
|
23
|
+
# object that is appropraite for the user to return to
|
24
|
+
menu = main_menu
|
25
|
+
while true
|
26
|
+
menu = menu.retreive_selection
|
27
|
+
end
|
28
|
+
|
data/demo/menus.rb
ADDED
@@ -0,0 +1,82 @@
|
|
1
|
+
require_relative 'demo_environment'
|
2
|
+
FAVORITE_FOODS = []
|
3
|
+
|
4
|
+
puts 'hello'
|
5
|
+
# Creating the main menu #
|
6
|
+
def main_menu
|
7
|
+
|
8
|
+
# Step 1, create the entries with (display text, method(:to_be_called), optional_args)
|
9
|
+
|
10
|
+
hello = GemMenu::Entry.new('hello', method(:hello_world))
|
11
|
+
world = GemMenu::Entry.new('world', method(:counting_world))
|
12
|
+
second_menu = GemMenu::Entry.new('2nd level', method(:menu_2))
|
13
|
+
food_menu = GemMenu::Entry.new('food menu', method(:menu_favorite_foods))
|
14
|
+
|
15
|
+
# Step 2, once entries are created, create the Menu object and return it with
|
16
|
+
# (title text, array_of_Entries, optional_args)
|
17
|
+
GemMenu::Menu.new('main menu', [hello, world, second_menu, food_menu])
|
18
|
+
end
|
19
|
+
|
20
|
+
def menu_2
|
21
|
+
|
22
|
+
# Similar to above but note the optional_args hash that is created below
|
23
|
+
bar = GemMenu::Entry.new('bar', method(:bar))
|
24
|
+
foo = GemMenu::Entry.new('foo', method(:foo))
|
25
|
+
optional_args = {:previous_menu => method(:main_menu)}
|
26
|
+
|
27
|
+
# optional_args can track the :previous_menu or :parameters to be passed on
|
28
|
+
GemMenu::Menu.new('my 2nd menu', [foo,bar], optional_args)
|
29
|
+
end
|
30
|
+
|
31
|
+
def menu_favorite_foods
|
32
|
+
|
33
|
+
# Here we are using a global array to track favorite foods. The first .each loop
|
34
|
+
# creates menu entries for each item in the FAVORITE_FOODS array. It also passes
|
35
|
+
# the food string on as a parameter in the optional_args hash. Also note, the
|
36
|
+
# method being called, :say_fav_food, is not a menu.
|
37
|
+
menu_entries = []
|
38
|
+
FAVORITE_FOODS.each do |food|
|
39
|
+
optional_args = {parameters: food}
|
40
|
+
menu_entries << GemMenu::Entry.new(food, method(:say_fav_food), optional_args)
|
41
|
+
end
|
42
|
+
|
43
|
+
# After creating the list of foods, it adds an option to add foods to the list.
|
44
|
+
# This Entry didn't need a :parameter passed on to it.
|
45
|
+
menu_entries << GemMenu::Entry.new('add food', method(:add_fav_food))
|
46
|
+
|
47
|
+
# Finally, create and return the Menu object, giving it a reference to the
|
48
|
+
# previous menu
|
49
|
+
optional_args = {previous_menu: method(:main_menu)}
|
50
|
+
GemMenu::Menu.new('my favorite foods', menu_entries, optional_args)
|
51
|
+
end
|
52
|
+
|
53
|
+
def say_fav_food(food)
|
54
|
+
puts "One of your favorite foods is #{food}"
|
55
|
+
menu_favorite_foods
|
56
|
+
end
|
57
|
+
|
58
|
+
def add_fav_food
|
59
|
+
puts "Enter one of your favorite foods: "
|
60
|
+
new_food = gets.strip
|
61
|
+
FAVORITE_FOODS << new_food
|
62
|
+
puts "#{new_food} added to the list"
|
63
|
+
menu_favorite_foods
|
64
|
+
end
|
65
|
+
|
66
|
+
def hello_world
|
67
|
+
puts 'hello world'
|
68
|
+
main_menu
|
69
|
+
end
|
70
|
+
|
71
|
+
def counting_world
|
72
|
+
(1..10).each do |i|
|
73
|
+
puts i
|
74
|
+
end
|
75
|
+
main_menu
|
76
|
+
end
|
77
|
+
|
78
|
+
menu = main_menu
|
79
|
+
while true
|
80
|
+
menu = menu.retreive_selection
|
81
|
+
end
|
82
|
+
|
data/demo/methods.rb
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
# From here down are the various methods that get called by the Entries from
|
2
|
+
# the menus above. The key to the methods that are called from the Entry class
|
3
|
+
# is that they need to return a menu method that represents which menu the user
|
4
|
+
# should be returned to when finished. If not, it will crash. To launch the CLI
|
5
|
+
# see the last few lines of the file.
|
6
|
+
|
7
|
+
def say_fav_food(food)
|
8
|
+
puts "One of your favorite foods is #{food}"
|
9
|
+
menu_favorite_foods
|
10
|
+
end
|
11
|
+
|
12
|
+
def add_fav_food
|
13
|
+
puts "Enter one of your favorite foods: "
|
14
|
+
new_food = gets.strip
|
15
|
+
FAVORITE_FOODS << new_food
|
16
|
+
puts "#{new_food} added to the list"
|
17
|
+
menu_favorite_foods
|
18
|
+
end
|
19
|
+
|
20
|
+
def hello_world
|
21
|
+
puts 'hello world'
|
22
|
+
main_menu
|
23
|
+
end
|
24
|
+
|
25
|
+
def counting_world
|
26
|
+
(1..10).each do |i|
|
27
|
+
puts i
|
28
|
+
end
|
29
|
+
main_menu
|
30
|
+
end
|
31
|
+
|
32
|
+
def foo
|
33
|
+
puts 'foo'
|
34
|
+
menu_2
|
35
|
+
end
|
36
|
+
|
37
|
+
# Notice below, even though :bar is launched from menu 2, it is sending
|
38
|
+
# main_menu as it's return. Occasionally it might not make sense for the user to
|
39
|
+
# return to the menu they left from. This is one advantage to explicitly calling the menu to return to.
|
40
|
+
def bar
|
41
|
+
puts 'bar'
|
42
|
+
main_menu
|
43
|
+
end
|
data/gem_menu.gemspec
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
|
2
|
+
lib = File.expand_path("../lib", __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require "gem_menu/version"
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "gem_menu"
|
8
|
+
spec.version = GemMenu::VERSION
|
9
|
+
spec.authors = ["brad schrag"]
|
10
|
+
spec.email = ["brad.schrag@gmail.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{A RubyGem for creating simple, text based, nested menus.}
|
13
|
+
spec.description = %q{GemMenu allows a user to easily create a menu interface for a CLI or other text based app.}
|
14
|
+
spec.homepage = "https://github.com/bschrag620/gem_menu"
|
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"] = "https://rubygems.org"
|
21
|
+
|
22
|
+
spec.metadata["homepage_uri"] = spec.homepage
|
23
|
+
spec.metadata["source_code_uri"] = "https://github.com/bschrag620/gem_menu"
|
24
|
+
spec.metadata["changelog_uri"] = "https://github.com/bschrag620/gem_menu"
|
25
|
+
else
|
26
|
+
raise "RubyGems 2.0 or newer is required to protect against " \
|
27
|
+
"public gem pushes."
|
28
|
+
end
|
29
|
+
|
30
|
+
# Specify which files should be added to the gem when it is released.
|
31
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
32
|
+
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
33
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
34
|
+
end
|
35
|
+
spec.bindir = "exe"
|
36
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
37
|
+
spec.require_paths = ["lib"]
|
38
|
+
|
39
|
+
spec.add_development_dependency "bundler", "~> 1.17"
|
40
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
41
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
42
|
+
spec.add_dependency 'colorize', '~> 0.8.1'
|
43
|
+
end
|
data/lib/gem_menu.rb
ADDED
@@ -0,0 +1,110 @@
|
|
1
|
+
require_relative "./gem_menu/version"
|
2
|
+
require "colorize"
|
3
|
+
|
4
|
+
module GemMenu
|
5
|
+
class Error < StandardError; end
|
6
|
+
|
7
|
+
class Entry
|
8
|
+
attr_accessor :name, :next_method, :parameters, :previous
|
9
|
+
|
10
|
+
def initialize(name, next_method, optional_args=nil)
|
11
|
+
self.name = name
|
12
|
+
self.next_method = next_method
|
13
|
+
if optional_args
|
14
|
+
optional_args.each do |key, value|
|
15
|
+
self.send("#{key}=", value)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def to_s
|
21
|
+
self.name
|
22
|
+
end
|
23
|
+
|
24
|
+
def execute_selection(method)
|
25
|
+
if self.parameters
|
26
|
+
method.call(self.parameters)
|
27
|
+
else
|
28
|
+
method.call
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def next_selection
|
33
|
+
execute_selection(self.next_method)
|
34
|
+
end
|
35
|
+
|
36
|
+
def previous_selection
|
37
|
+
self.previous.call
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
class Menu
|
42
|
+
attr_accessor :title, :entries, :previous_menu, :parameter, :menu_hash
|
43
|
+
|
44
|
+
@@exit = Entry.new('exit', method(:exit))
|
45
|
+
@@menu_char_begin = "<== ".colorize(:light_blue)
|
46
|
+
@@menu_char_end = " ==>".colorize(:light_blue)
|
47
|
+
|
48
|
+
def initialize(title, entries, optional_args=nil)
|
49
|
+
self.title = title
|
50
|
+
self.entries = entries
|
51
|
+
if optional_args
|
52
|
+
optional_args.each do |key, value|
|
53
|
+
self.send("#{key}=", value)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
self.menu_hash = {"x" => self.exit_method}
|
57
|
+
self.set_choices
|
58
|
+
end
|
59
|
+
|
60
|
+
def exit_method
|
61
|
+
@@exit
|
62
|
+
end
|
63
|
+
|
64
|
+
def menu_char_begin
|
65
|
+
@@menu_char_begin
|
66
|
+
end
|
67
|
+
|
68
|
+
def menu_char_end
|
69
|
+
@@menu_char_end
|
70
|
+
end
|
71
|
+
|
72
|
+
def set_choices
|
73
|
+
self.entries.each.with_index(1) do |entry, i|
|
74
|
+
self.menu_hash[i.to_s] = entry
|
75
|
+
end
|
76
|
+
if self.previous_menu
|
77
|
+
self.menu_hash['b'] = GemMenu::Entry.new('back', self.previous_menu)
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
def retreive_selection
|
82
|
+
display_menu
|
83
|
+
puts "Please make your selection:".colorize(:light_green)
|
84
|
+
receive_input
|
85
|
+
end
|
86
|
+
|
87
|
+
def display_menu
|
88
|
+
puts
|
89
|
+
puts "#{self.menu_char_begin}#{self.title}#{self.menu_char_end}"
|
90
|
+
menu_hash.sort.to_h.each do |user_choice, description|
|
91
|
+
puts "#{user_choice.colorize(:light_yellow)}) #{description}"
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
def receive_input
|
96
|
+
selection = nil
|
97
|
+
while !self.menu_hash.include?(selection)
|
98
|
+
selection = gets.strip.downcase
|
99
|
+
if !self.menu_hash.include?(selection)
|
100
|
+
puts "Invalid selection"
|
101
|
+
end
|
102
|
+
end
|
103
|
+
launch_selection(selection)
|
104
|
+
end
|
105
|
+
|
106
|
+
def launch_selection(selection)
|
107
|
+
self.menu_hash[selection].next_selection
|
108
|
+
end
|
109
|
+
end
|
110
|
+
end
|
metadata
ADDED
@@ -0,0 +1,123 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: gem_menu
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.2.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- brad schrag
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-12-11 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.17'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.17'
|
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: colorize
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 0.8.1
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 0.8.1
|
69
|
+
description: GemMenu allows a user to easily create a menu interface for a CLI or
|
70
|
+
other text based app.
|
71
|
+
email:
|
72
|
+
- brad.schrag@gmail.com
|
73
|
+
executables: []
|
74
|
+
extensions: []
|
75
|
+
extra_rdoc_files: []
|
76
|
+
files:
|
77
|
+
- ".gitignore"
|
78
|
+
- ".rspec"
|
79
|
+
- ".travis.yml"
|
80
|
+
- CODE_OF_CONDUCT.md
|
81
|
+
- Gemfile
|
82
|
+
- Gemfile.lock
|
83
|
+
- LICENSE.txt
|
84
|
+
- README.md
|
85
|
+
- Rakefile
|
86
|
+
- bin/console
|
87
|
+
- bin/setup
|
88
|
+
- demo/demo_environment.rb
|
89
|
+
- demo/menu_demo.rb
|
90
|
+
- demo/menus.rb
|
91
|
+
- demo/methods.rb
|
92
|
+
- gem_menu.gemspec
|
93
|
+
- lib/gem_menu.rb
|
94
|
+
- lib/gem_menu/version.rb
|
95
|
+
homepage: https://github.com/bschrag620/gem_menu
|
96
|
+
licenses:
|
97
|
+
- MIT
|
98
|
+
metadata:
|
99
|
+
allowed_push_host: https://rubygems.org
|
100
|
+
homepage_uri: https://github.com/bschrag620/gem_menu
|
101
|
+
source_code_uri: https://github.com/bschrag620/gem_menu
|
102
|
+
changelog_uri: https://github.com/bschrag620/gem_menu
|
103
|
+
post_install_message:
|
104
|
+
rdoc_options: []
|
105
|
+
require_paths:
|
106
|
+
- lib
|
107
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
108
|
+
requirements:
|
109
|
+
- - ">="
|
110
|
+
- !ruby/object:Gem::Version
|
111
|
+
version: '0'
|
112
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
113
|
+
requirements:
|
114
|
+
- - ">="
|
115
|
+
- !ruby/object:Gem::Version
|
116
|
+
version: '0'
|
117
|
+
requirements: []
|
118
|
+
rubyforge_project:
|
119
|
+
rubygems_version: 2.7.8
|
120
|
+
signing_key:
|
121
|
+
specification_version: 4
|
122
|
+
summary: A RubyGem for creating simple, text based, nested menus.
|
123
|
+
test_files: []
|