sw_tour 0.1.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 +7 -0
- data/.gitignore +9 -0
- data/.vscode/launch.json +14 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +7 -0
- data/Gemfile.lock +37 -0
- data/LICENSE.txt +21 -0
- data/README.md +42 -0
- data/Rakefile +2 -0
- data/bin/bundle +114 -0
- data/bin/console +14 -0
- data/bin/rake +29 -0
- data/bin/setup +8 -0
- data/bin/sw_tour +5 -0
- data/lib/sw_tour.rb +11 -0
- data/lib/sw_tour/API.rb +38 -0
- data/lib/sw_tour/CLI.rb +100 -0
- data/lib/sw_tour/people.rb +45 -0
- data/lib/sw_tour/planets.rb +57 -0
- data/lib/sw_tour/starships.rb +36 -0
- data/lib/sw_tour/version.rb +3 -0
- data/sw_tour.gemspec +24 -0
- metadata +66 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: fbb9090de95a992c6a2ca0cc24748d156002ac2a0e9071391d94a022c46cbe4f
|
|
4
|
+
data.tar.gz: 0e777b3d141b4d48902257c915521d48930a870d34ceadb3822f0b19e2bd58f9
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 189f66e4a47786888436a80c3ef9ca026fd21bb0b7660f6ef9bf9926d6e7abea29ca1432405374754955e8d396083378f80c2534e8efe1b0672c30191a964876
|
|
7
|
+
data.tar.gz: 5c50b4803702f767ce4ca63bcd9929180858cc851536c012acf8251a6434688d455462e93ac9b4f3b24b7dfd9ae070c6371acd394b3bf552adb9d61b8d96a359
|
data/.gitignore
ADDED
data/.vscode/launch.json
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
{
|
|
2
|
+
// Use IntelliSense to learn about possible attributes.
|
|
3
|
+
// Hover to view descriptions of existing attributes.
|
|
4
|
+
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
|
|
5
|
+
"version": "0.2.0",
|
|
6
|
+
"configurations": [
|
|
7
|
+
{
|
|
8
|
+
"name": "Debug Local File",
|
|
9
|
+
"type": "Ruby",
|
|
10
|
+
"request": "launch",
|
|
11
|
+
"program": "${workspaceRoot}/bin/sw_tour"
|
|
12
|
+
}
|
|
13
|
+
]
|
|
14
|
+
}
|
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 carrieburks@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 [https://contributor-covenant.org/version/1/4][version]
|
|
72
|
+
|
|
73
|
+
[homepage]: https://contributor-covenant.org
|
|
74
|
+
[version]: https://contributor-covenant.org/version/1/4/
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
PATH
|
|
2
|
+
remote: .
|
|
3
|
+
specs:
|
|
4
|
+
sw_tour (0.1.0)
|
|
5
|
+
|
|
6
|
+
GEM
|
|
7
|
+
remote: https://rubygems.org/
|
|
8
|
+
specs:
|
|
9
|
+
domain_name (0.5.20190701)
|
|
10
|
+
unf (>= 0.0.5, < 1.0.0)
|
|
11
|
+
http-accept (1.7.0)
|
|
12
|
+
http-cookie (1.0.3)
|
|
13
|
+
domain_name (~> 0.5)
|
|
14
|
+
mime-types (3.3.1)
|
|
15
|
+
mime-types-data (~> 3.2015)
|
|
16
|
+
mime-types-data (3.2021.0225)
|
|
17
|
+
netrc (0.11.0)
|
|
18
|
+
rake (12.3.3)
|
|
19
|
+
rest-client (2.1.0)
|
|
20
|
+
http-accept (>= 1.7.0, < 2.0)
|
|
21
|
+
http-cookie (>= 1.0.2, < 2.0)
|
|
22
|
+
mime-types (>= 1.16, < 4.0)
|
|
23
|
+
netrc (~> 0.8)
|
|
24
|
+
unf (0.1.4)
|
|
25
|
+
unf_ext
|
|
26
|
+
unf_ext (0.0.7.7)
|
|
27
|
+
|
|
28
|
+
PLATFORMS
|
|
29
|
+
ruby
|
|
30
|
+
|
|
31
|
+
DEPENDENCIES
|
|
32
|
+
rake (~> 12.0)
|
|
33
|
+
rest-client
|
|
34
|
+
sw_tour!
|
|
35
|
+
|
|
36
|
+
BUNDLED WITH
|
|
37
|
+
2.2.11
|
data/LICENSE.txt
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2020 carriemathieu
|
|
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,42 @@
|
|
|
1
|
+
# SwTour
|
|
2
|
+
|
|
3
|
+
May the force be with you! This Ruby Gem uses the Star Wars API to travel through the Star Wars universe! You can choose your own spaceship and planet, while finding out fun facts about both.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
Add this line to your application's Gemfile:
|
|
8
|
+
|
|
9
|
+
```ruby
|
|
10
|
+
gem 'sw_tour'
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
And then execute:
|
|
14
|
+
|
|
15
|
+
$ bundle install
|
|
16
|
+
|
|
17
|
+
Or install it yourself as:
|
|
18
|
+
|
|
19
|
+
$ gem install sw_tour
|
|
20
|
+
|
|
21
|
+
## Usage
|
|
22
|
+
|
|
23
|
+
Run the program by ./bin/sw_tour in your terminal, and follow the prompts.
|
|
24
|
+
|
|
25
|
+
## Development
|
|
26
|
+
|
|
27
|
+
After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
|
28
|
+
|
|
29
|
+
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).
|
|
30
|
+
|
|
31
|
+
## Contributing
|
|
32
|
+
|
|
33
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/carriemathieu/sw_tour. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/carriemathieu/sw_tour/blob/master/CODE_OF_CONDUCT.md).
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
## License
|
|
37
|
+
|
|
38
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
|
39
|
+
|
|
40
|
+
## Code of Conduct
|
|
41
|
+
|
|
42
|
+
Everyone interacting in the SwTour project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/sw_tour/blob/master/CODE_OF_CONDUCT.md).
|
data/Rakefile
ADDED
data/bin/bundle
ADDED
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
# frozen_string_literal: true
|
|
3
|
+
|
|
4
|
+
#
|
|
5
|
+
# This file was generated by Bundler.
|
|
6
|
+
#
|
|
7
|
+
# The application 'bundle' is installed as part of a gem, and
|
|
8
|
+
# this file is here to facilitate running it.
|
|
9
|
+
#
|
|
10
|
+
|
|
11
|
+
require "rubygems"
|
|
12
|
+
|
|
13
|
+
m = Module.new do
|
|
14
|
+
module_function
|
|
15
|
+
|
|
16
|
+
def invoked_as_script?
|
|
17
|
+
File.expand_path($0) == File.expand_path(__FILE__)
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def env_var_version
|
|
21
|
+
ENV["BUNDLER_VERSION"]
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def cli_arg_version
|
|
25
|
+
return unless invoked_as_script? # don't want to hijack other binstubs
|
|
26
|
+
return unless "update".start_with?(ARGV.first || " ") # must be running `bundle update`
|
|
27
|
+
bundler_version = nil
|
|
28
|
+
update_index = nil
|
|
29
|
+
ARGV.each_with_index do |a, i|
|
|
30
|
+
if update_index && update_index.succ == i && a =~ Gem::Version::ANCHORED_VERSION_PATTERN
|
|
31
|
+
bundler_version = a
|
|
32
|
+
end
|
|
33
|
+
next unless a =~ /\A--bundler(?:[= ](#{Gem::Version::VERSION_PATTERN}))?\z/
|
|
34
|
+
bundler_version = $1
|
|
35
|
+
update_index = i
|
|
36
|
+
end
|
|
37
|
+
bundler_version
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def gemfile
|
|
41
|
+
gemfile = ENV["BUNDLE_GEMFILE"]
|
|
42
|
+
return gemfile if gemfile && !gemfile.empty?
|
|
43
|
+
|
|
44
|
+
File.expand_path("../../Gemfile", __FILE__)
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
def lockfile
|
|
48
|
+
lockfile =
|
|
49
|
+
case File.basename(gemfile)
|
|
50
|
+
when "gems.rb" then gemfile.sub(/\.rb$/, gemfile)
|
|
51
|
+
else "#{gemfile}.lock"
|
|
52
|
+
end
|
|
53
|
+
File.expand_path(lockfile)
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
def lockfile_version
|
|
57
|
+
return unless File.file?(lockfile)
|
|
58
|
+
lockfile_contents = File.read(lockfile)
|
|
59
|
+
return unless lockfile_contents =~ /\n\nBUNDLED WITH\n\s{2,}(#{Gem::Version::VERSION_PATTERN})\n/
|
|
60
|
+
Regexp.last_match(1)
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
def bundler_version
|
|
64
|
+
@bundler_version ||=
|
|
65
|
+
env_var_version || cli_arg_version ||
|
|
66
|
+
lockfile_version
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
def bundler_requirement
|
|
70
|
+
return "#{Gem::Requirement.default}.a" unless bundler_version
|
|
71
|
+
|
|
72
|
+
bundler_gem_version = Gem::Version.new(bundler_version)
|
|
73
|
+
|
|
74
|
+
requirement = bundler_gem_version.approximate_recommendation
|
|
75
|
+
|
|
76
|
+
return requirement unless Gem::Version.new(Gem::VERSION) < Gem::Version.new("2.7.0")
|
|
77
|
+
|
|
78
|
+
requirement += ".a" if bundler_gem_version.prerelease?
|
|
79
|
+
|
|
80
|
+
requirement
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
def load_bundler!
|
|
84
|
+
ENV["BUNDLE_GEMFILE"] ||= gemfile
|
|
85
|
+
|
|
86
|
+
activate_bundler
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
def activate_bundler
|
|
90
|
+
gem_error = activation_error_handling do
|
|
91
|
+
gem "bundler", bundler_requirement
|
|
92
|
+
end
|
|
93
|
+
return if gem_error.nil?
|
|
94
|
+
require_error = activation_error_handling do
|
|
95
|
+
require "bundler/version"
|
|
96
|
+
end
|
|
97
|
+
return if require_error.nil? && Gem::Requirement.new(bundler_requirement).satisfied_by?(Gem::Version.new(Bundler::VERSION))
|
|
98
|
+
warn "Activating bundler (#{bundler_requirement}) failed:\n#{gem_error.message}\n\nTo install the version of bundler this project requires, run `gem install bundler -v '#{bundler_requirement}'`"
|
|
99
|
+
exit 42
|
|
100
|
+
end
|
|
101
|
+
|
|
102
|
+
def activation_error_handling
|
|
103
|
+
yield
|
|
104
|
+
nil
|
|
105
|
+
rescue StandardError, LoadError => e
|
|
106
|
+
e
|
|
107
|
+
end
|
|
108
|
+
end
|
|
109
|
+
|
|
110
|
+
m.load_bundler!
|
|
111
|
+
|
|
112
|
+
if m.invoked_as_script?
|
|
113
|
+
load Gem.bin_path("bundler", "bundle")
|
|
114
|
+
end
|
data/bin/console
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
|
|
3
|
+
require "bundler/setup"
|
|
4
|
+
require "sw_tour"
|
|
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/rake
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
# frozen_string_literal: true
|
|
3
|
+
|
|
4
|
+
#
|
|
5
|
+
# This file was generated by Bundler.
|
|
6
|
+
#
|
|
7
|
+
# The application 'rake' is installed as part of a gem, and
|
|
8
|
+
# this file is here to facilitate running it.
|
|
9
|
+
#
|
|
10
|
+
|
|
11
|
+
require "pathname"
|
|
12
|
+
ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
|
|
13
|
+
Pathname.new(__FILE__).realpath)
|
|
14
|
+
|
|
15
|
+
bundle_binstub = File.expand_path("../bundle", __FILE__)
|
|
16
|
+
|
|
17
|
+
if File.file?(bundle_binstub)
|
|
18
|
+
if File.read(bundle_binstub, 300) =~ /This file was generated by Bundler/
|
|
19
|
+
load(bundle_binstub)
|
|
20
|
+
else
|
|
21
|
+
abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run.
|
|
22
|
+
Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.")
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
require "rubygems"
|
|
27
|
+
require "bundler/setup"
|
|
28
|
+
|
|
29
|
+
load Gem.bin_path("rake", "rake")
|
data/bin/setup
ADDED
data/bin/sw_tour
ADDED
data/lib/sw_tour.rb
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
require 'pry'
|
|
2
|
+
require 'rest-client'
|
|
3
|
+
require 'json'
|
|
4
|
+
require 'colorize'
|
|
5
|
+
|
|
6
|
+
require_relative "./sw_tour/version"
|
|
7
|
+
require_relative "./sw_tour/CLI"
|
|
8
|
+
require_relative "./sw_tour/planets"
|
|
9
|
+
require_relative "./sw_tour/API"
|
|
10
|
+
require_relative "./sw_tour/starships"
|
|
11
|
+
require_relative "./sw_tour/people"
|
data/lib/sw_tour/API.rb
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
class SwTour::API
|
|
2
|
+
|
|
3
|
+
# gets starships from API, parses data & nested data, instantiates new object in Starship class
|
|
4
|
+
def self.get_starships
|
|
5
|
+
starships = RestClient.get('https://www.swapi.tech/api/starships/')
|
|
6
|
+
@starship = JSON.parse(starships)
|
|
7
|
+
@starship["results"].each do |ship|
|
|
8
|
+
id = ship["uid"].to_i
|
|
9
|
+
info = RestClient.get("https://www.swapi.tech/api/starships/#{id}")
|
|
10
|
+
ship_info = JSON.parse(info)["result"]["properties"]
|
|
11
|
+
SwTour::Starship.new(ship_info)
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
# gets planets from API, parses data & nested data, instantiates new object in Starship class
|
|
16
|
+
def self.get_planets
|
|
17
|
+
planets = RestClient.get("https://www.swapi.tech/api/planets/")
|
|
18
|
+
@planets = JSON.parse(planets)
|
|
19
|
+
@planets["results"].each do |planet|
|
|
20
|
+
id = planet["uid"].to_i
|
|
21
|
+
info = RestClient.get("https://www.swapi.tech/api/planets/#{id}")
|
|
22
|
+
planet_info = JSON.parse(info)["result"]["properties"]
|
|
23
|
+
SwTour::Planet.new(planet_info)
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
# gets people from API, parses data & nested data, instantiates new object in Starship class
|
|
28
|
+
def self.get_people
|
|
29
|
+
people = RestClient.get("https://www.swapi.tech/api/people/")
|
|
30
|
+
@people = JSON.parse(people)
|
|
31
|
+
@people["results"].each do |person|
|
|
32
|
+
id = person["uid"].to_i
|
|
33
|
+
info = RestClient.get("https://www.swapi.tech/api/people/#{id}")
|
|
34
|
+
person_info = JSON.parse(info)["result"]["properties"]
|
|
35
|
+
SwTour::People.new(person_info)
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
end
|
data/lib/sw_tour/CLI.rb
ADDED
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
class SwTour::CLI
|
|
3
|
+
|
|
4
|
+
## app flow
|
|
5
|
+
|
|
6
|
+
# start
|
|
7
|
+
def self.start
|
|
8
|
+
puts "\n☆.。.:*・°☆.。.:*・°☆.。.:*・°☆.。.:*・°"
|
|
9
|
+
puts "\n\u{1F680} Welcome to Star Wars Travel Agency! \u{1F916}"
|
|
10
|
+
puts "*****************************************"
|
|
11
|
+
puts "\nChewie will be your pilot today! Which spaceship will you be using?"
|
|
12
|
+
starship
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def self.starship
|
|
16
|
+
# gets starship info from API
|
|
17
|
+
SwTour::Starship.display_starships
|
|
18
|
+
puts "\nPlease enter the number for your selected spaceship."
|
|
19
|
+
|
|
20
|
+
# prompts user for input
|
|
21
|
+
input = gets.chomp
|
|
22
|
+
ship = input.to_i
|
|
23
|
+
|
|
24
|
+
# checks to make sure input is valid
|
|
25
|
+
until ship <= SwTour::Starship.all.length && ship > 0
|
|
26
|
+
puts "Please enter a valid number."
|
|
27
|
+
input = gets.chomp
|
|
28
|
+
ship = input.to_i
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
# gets info for starship from input
|
|
32
|
+
chosen_starship = SwTour::Starship.all[ship - 1]
|
|
33
|
+
chosen_starship.starship_info
|
|
34
|
+
|
|
35
|
+
# allocates time to read starship info
|
|
36
|
+
sleep(3)
|
|
37
|
+
puts "\nYou get to pick a travel companion! Who would you like to take with you?"
|
|
38
|
+
people
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
def self.people
|
|
42
|
+
# gets people info from API
|
|
43
|
+
SwTour::People.display_people
|
|
44
|
+
|
|
45
|
+
# prompts user for input
|
|
46
|
+
input = gets.chomp
|
|
47
|
+
person = input.to_i
|
|
48
|
+
|
|
49
|
+
# checks to make sure input is valid
|
|
50
|
+
until person <= SwTour::People.all.length && person > 0
|
|
51
|
+
puts "Please enter a valid number."
|
|
52
|
+
input = gets.chomp
|
|
53
|
+
person = input.to_i
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
# gets info for person from input
|
|
57
|
+
chosen_person = SwTour::People.all[person-1]
|
|
58
|
+
chosen_person.person_info
|
|
59
|
+
|
|
60
|
+
planets
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
def self.planets
|
|
64
|
+
# gets planet info from API
|
|
65
|
+
SwTour::Planet.display_planets
|
|
66
|
+
|
|
67
|
+
# gets planet input
|
|
68
|
+
input = gets.chomp
|
|
69
|
+
planet = input.to_i
|
|
70
|
+
|
|
71
|
+
# validates planet info
|
|
72
|
+
until planet <= SwTour::Planet.all.length && planet > 0
|
|
73
|
+
puts "Please enter a valid number."
|
|
74
|
+
input = gets.chomp
|
|
75
|
+
planet = input.to_i
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
# gets info for planet from input
|
|
79
|
+
chosen_planet = SwTour::Planet.all[planet - 1]
|
|
80
|
+
chosen_planet.planet_info
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
def self.travel_again?
|
|
84
|
+
puts "Would you like to travel again? Please input 'yes' to travel again or 'exit' to exit."
|
|
85
|
+
input = gets.chomp.downcase
|
|
86
|
+
if input == "yes"
|
|
87
|
+
start
|
|
88
|
+
elsif input == "exit"
|
|
89
|
+
goodbye
|
|
90
|
+
else
|
|
91
|
+
puts "Please enter 'yes' or 'exit' "
|
|
92
|
+
travel_again?
|
|
93
|
+
end
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
def self.goodbye
|
|
97
|
+
puts "We'll see you next time!"
|
|
98
|
+
exit(true)
|
|
99
|
+
end
|
|
100
|
+
end
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
class SwTour::People
|
|
2
|
+
attr_accessor :name, :eye_color, :height, :gender
|
|
3
|
+
|
|
4
|
+
@@all = []
|
|
5
|
+
|
|
6
|
+
def initialize(person_info)
|
|
7
|
+
@name = person_info["name"]
|
|
8
|
+
@height = person_info["height"]
|
|
9
|
+
@gender = person_info["gender"]
|
|
10
|
+
@eye_color = person_info["eye_color"]
|
|
11
|
+
@@all << self
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def self.display_people
|
|
15
|
+
SwTour::API.get_people if @@all.empty?
|
|
16
|
+
@@all.each.with_index(1) do |person, index|
|
|
17
|
+
puts "#{index}. #{person.name}".colorize(:light_green)
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def person_info
|
|
22
|
+
if self.name == "Darth Vader"
|
|
23
|
+
puts "\n\u{1F6A8} OH NO! Darth Vader has run off with your ship! :(.".colorize(:white).bold
|
|
24
|
+
puts "\nLooks like we'll have to choose another ship. What ship will you choose this time?\n\n"
|
|
25
|
+
SwTour::CLI.starship
|
|
26
|
+
else
|
|
27
|
+
puts "#{self.name} - good choice! First we'll need to go pick up your companion then we'll head to your final destination.\n"
|
|
28
|
+
puts "Keep an eye out for your companion! This is what you should look for: \n".colorize(:magenta)
|
|
29
|
+
puts "Gender: #{self.gender}\n"
|
|
30
|
+
puts "Height: #{self.height}cm\n"
|
|
31
|
+
puts "Eye Color: #{self.eye_color}\n"
|
|
32
|
+
puts "***************************************************"
|
|
33
|
+
puts "\u{1F311} \u{1F312} \u{1F313} \u{1F314} \u{1F315} \u{1F316} \u{1F317} \u{1F318}"
|
|
34
|
+
puts "***************************************************"
|
|
35
|
+
sleep(5)
|
|
36
|
+
puts "Perfect! We have picked up #{self.name}! \n\n"
|
|
37
|
+
puts "Time to choose your destination:\n"
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
def self.all
|
|
42
|
+
@@all
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
end
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
class SwTour::Planet
|
|
2
|
+
attr_accessor :name, :climate, :terrain, :population
|
|
3
|
+
|
|
4
|
+
@@all = []
|
|
5
|
+
|
|
6
|
+
def initialize(planet_info)
|
|
7
|
+
@name = planet_info["name"]
|
|
8
|
+
@climate = planet_info["climate"]
|
|
9
|
+
@terrain = planet_info["terrain"]
|
|
10
|
+
@population = planet_info["population"]
|
|
11
|
+
@@all << self
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def self.display_planets
|
|
15
|
+
SwTour::API.get_planets if @@all.empty?
|
|
16
|
+
@@all.each.with_index(1) do |planet, index|
|
|
17
|
+
puts "#{index}. #{planet.name}".colorize(:light_green)
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def planet_info
|
|
22
|
+
if self.climate == "frozen"
|
|
23
|
+
puts "\nBrrr... I hope you brought some warm clothes!".colorize(:light_blue)
|
|
24
|
+
elsif self.climate == "temperate"
|
|
25
|
+
puts "\nLooks like we have some great weather!".colorize(:light_red)
|
|
26
|
+
elsif self.terrain.include?("swamp") || self.terrain.include?("jungle")
|
|
27
|
+
puts "\nIt might be a bit muddy!".colorize(:green)
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
puts "\n\u{1F4AB} Chewie says we're ready. Off we go! While we're on our way, here is some information about #{self.name}: "
|
|
31
|
+
puts "Climate: #{self.climate}".colorize(:light_yellow)
|
|
32
|
+
puts "Terrain: #{self.terrain}".colorize(:light_yellow)
|
|
33
|
+
puts "Population: #{self.population}".colorize(:light_yellow)
|
|
34
|
+
sleep(5)
|
|
35
|
+
puts "\n\u{1F320} Welcome to #{self.name}! \u{1F320}"
|
|
36
|
+
puts "
|
|
37
|
+
* . * . *
|
|
38
|
+
* . . *
|
|
39
|
+
* . * . . *
|
|
40
|
+
. * .
|
|
41
|
+
. . * * .
|
|
42
|
+
. . .
|
|
43
|
+
. * * *
|
|
44
|
+
. .
|
|
45
|
+
* . *"
|
|
46
|
+
|
|
47
|
+
#This ASCII pic can be found at
|
|
48
|
+
#https://asciiart.website/index.php?art=nature/astronomy
|
|
49
|
+
|
|
50
|
+
SwTour::CLI.travel_again?
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
def self.all
|
|
54
|
+
@@all
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
end
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
class SwTour::Starship
|
|
2
|
+
attr_accessor :starship, :name, :model, :manufacturer, :crew
|
|
3
|
+
|
|
4
|
+
@@all = []
|
|
5
|
+
@@dark_side = ["Star Destroyer", "Death Star", "TIE Advanced x1", "Executor", "Sentinel-class landing craft"]
|
|
6
|
+
|
|
7
|
+
def initialize(ship_info)
|
|
8
|
+
@name = ship_info["name"]
|
|
9
|
+
@model = ship_info["model"]
|
|
10
|
+
@manufacturer = ship_info["manufacturer"]
|
|
11
|
+
@crew = ship_info["crew"]
|
|
12
|
+
@@all << self
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def self.display_starships
|
|
16
|
+
SwTour::API.get_starships if @@all.empty?
|
|
17
|
+
@@all.each.with_index(1) do |ship, index|
|
|
18
|
+
puts "#{index}. #{ship.name}".colorize(:light_green)
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def starship_info
|
|
23
|
+
if @@dark_side.include?(self.name)
|
|
24
|
+
puts "\nLooks like you chose the dark side!".colorize(:red)
|
|
25
|
+
else
|
|
26
|
+
puts "\nGreat choice!"
|
|
27
|
+
end
|
|
28
|
+
puts "\nHere's some information about The #{self.name}:"
|
|
29
|
+
puts "The #{self.name}'s model is #{self.model} and was manufactured by #{self.manufacturer}. The #{self.name} consists of #{self.crew} crew members.".colorize(:light_yellow)
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def self.all
|
|
33
|
+
@@all
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
end
|
data/sw_tour.gemspec
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
require_relative 'lib/sw_tour/version'
|
|
2
|
+
|
|
3
|
+
Gem::Specification.new do |spec|
|
|
4
|
+
spec.name = "sw_tour"
|
|
5
|
+
spec.version = SwTour::VERSION
|
|
6
|
+
spec.authors = ["carriemathieu"]
|
|
7
|
+
spec.email = ["carrie.mathieu@gicloud.com"]
|
|
8
|
+
|
|
9
|
+
spec.summary = "Travel through the Star Wars Universe - choose your own spaceship, travel companion, and desination! Built using the Star Wars API - www.swapi.tech. Run SwTour::CLI.start to begin."
|
|
10
|
+
spec.homepage = "https://github.com/carriemathieu/sw_tour"
|
|
11
|
+
spec.license = "MIT"
|
|
12
|
+
spec.required_ruby_version = Gem::Requirement.new(">= 2.3.0")
|
|
13
|
+
|
|
14
|
+
# Specify which files should be added to the gem when it is released.
|
|
15
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
|
16
|
+
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
|
17
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
|
18
|
+
end
|
|
19
|
+
spec.bindir = "exe"
|
|
20
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
|
21
|
+
spec.require_paths = ["lib"]
|
|
22
|
+
|
|
23
|
+
#spec.add_development_dependency "pry"
|
|
24
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: sw_tour
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.1.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- carriemathieu
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: exe
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2021-03-25 00:00:00.000000000 Z
|
|
12
|
+
dependencies: []
|
|
13
|
+
description:
|
|
14
|
+
email:
|
|
15
|
+
- carrie.mathieu@gicloud.com
|
|
16
|
+
executables: []
|
|
17
|
+
extensions: []
|
|
18
|
+
extra_rdoc_files: []
|
|
19
|
+
files:
|
|
20
|
+
- ".gitignore"
|
|
21
|
+
- ".vscode/launch.json"
|
|
22
|
+
- CODE_OF_CONDUCT.md
|
|
23
|
+
- Gemfile
|
|
24
|
+
- Gemfile.lock
|
|
25
|
+
- LICENSE.txt
|
|
26
|
+
- README.md
|
|
27
|
+
- Rakefile
|
|
28
|
+
- bin/bundle
|
|
29
|
+
- bin/console
|
|
30
|
+
- bin/rake
|
|
31
|
+
- bin/setup
|
|
32
|
+
- bin/sw_tour
|
|
33
|
+
- lib/sw_tour.rb
|
|
34
|
+
- lib/sw_tour/API.rb
|
|
35
|
+
- lib/sw_tour/CLI.rb
|
|
36
|
+
- lib/sw_tour/people.rb
|
|
37
|
+
- lib/sw_tour/planets.rb
|
|
38
|
+
- lib/sw_tour/starships.rb
|
|
39
|
+
- lib/sw_tour/version.rb
|
|
40
|
+
- sw_tour.gemspec
|
|
41
|
+
homepage: https://github.com/carriemathieu/sw_tour
|
|
42
|
+
licenses:
|
|
43
|
+
- MIT
|
|
44
|
+
metadata: {}
|
|
45
|
+
post_install_message:
|
|
46
|
+
rdoc_options: []
|
|
47
|
+
require_paths:
|
|
48
|
+
- lib
|
|
49
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
50
|
+
requirements:
|
|
51
|
+
- - ">="
|
|
52
|
+
- !ruby/object:Gem::Version
|
|
53
|
+
version: 2.3.0
|
|
54
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
55
|
+
requirements:
|
|
56
|
+
- - ">="
|
|
57
|
+
- !ruby/object:Gem::Version
|
|
58
|
+
version: '0'
|
|
59
|
+
requirements: []
|
|
60
|
+
rubygems_version: 3.2.11
|
|
61
|
+
signing_key:
|
|
62
|
+
specification_version: 4
|
|
63
|
+
summary: Travel through the Star Wars Universe - choose your own spaceship, travel
|
|
64
|
+
companion, and desination! Built using the Star Wars API - www.swapi.tech. Run SwTour::CLI.start
|
|
65
|
+
to begin.
|
|
66
|
+
test_files: []
|