sw_characters 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +7 -0
- data/LICENSE.txt +21 -0
- data/README.md +37 -0
- data/Rakefile +2 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/bin/sw_characters +5 -0
- data/lib/sw_characters.rb +9 -0
- data/lib/sw_characters/api.rb +88 -0
- data/lib/sw_characters/character.rb +20 -0
- data/lib/sw_characters/cli.rb +215 -0
- data/lib/sw_characters/film.rb +17 -0
- data/lib/sw_characters/planet.rb +18 -0
- data/lib/sw_characters/species.rb +16 -0
- data/lib/sw_characters/version.rb +3 -0
- data/sw_characters.gemspec +39 -0
- metadata +93 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: da1b3321cd5d570d31e5965f90aa5d2359a143f49adc2af4096fd80b15bb0982
|
4
|
+
data.tar.gz: 5bcf61e423f10171bcd06b90e2f6dbe55373b65673ea5afa1b3abeeee7eaa1a4
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 3c57fce5657a12b6c7986e4bf7c574bb5e1a1ebf4272ba046c4fcc79cb3804832284f011dfa94e70d9c0b3bc2809f1deae0dceb708b49133f9bb78a830a392dc
|
7
|
+
data.tar.gz: '08298cd33336159bbf616a73d53b4064059f9a1ac85e929fec6f1d2690a74e9bcbd235782d2bfda5779edbd83ad912e112051f8676d0edb438826c2e2cf1fe10'
|
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 'grantsmith1256@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/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2018 'grant smith'
|
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,37 @@
|
|
1
|
+
# SwCharacters
|
2
|
+
|
3
|
+
## Description
|
4
|
+
|
5
|
+
The Star Wars Character Database is a self-updating encyclopedia of all named characters in the Star Wars movies. It also has additional information all planets and species in the Star Wars Universe, as well as most films (currently only updated through Episode 7).
|
6
|
+
|
7
|
+
## Video Demo
|
8
|
+
|
9
|
+
A video walkthrough can be found <a href="https://www.youtube.com/watch?v=kkgj5NtZ_bU">here</a>
|
10
|
+
|
11
|
+
|
12
|
+
## Installation
|
13
|
+
|
14
|
+
Just download all files from the repository and simply run in the terminal:
|
15
|
+
|
16
|
+
./bin/sw_characters
|
17
|
+
|
18
|
+
Then follow the onscreen instructions
|
19
|
+
|
20
|
+
## Usage
|
21
|
+
|
22
|
+
The program will load with 6 options.
|
23
|
+
|
24
|
+
Typing 1-4 will list the selected items in a numbered format. Type the number of the option you would like, then more information about that item will appear.
|
25
|
+
|
26
|
+
Typing 5 will allow you to search through the list of characters using their name. It will display a list format if there are multiple hits to your search, otherwise it will display the character info of the closest match. Please refrain from using any titles like "General" or "Emperor". The character list records their true names (or at least known names) and does not include titles.
|
27
|
+
|
28
|
+
Entering exit will exit the program
|
29
|
+
|
30
|
+
## License
|
31
|
+
|
32
|
+
The license for the program is included in the file directory: LICENSE.txt
|
33
|
+
|
34
|
+
|
35
|
+
## Contributing
|
36
|
+
|
37
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/mlmccor/sw_characters.
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "sw_characters"
|
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/bin/sw_characters
ADDED
@@ -0,0 +1,9 @@
|
|
1
|
+
require_relative "sw_characters/version"
|
2
|
+
require_relative './sw_characters/cli.rb'
|
3
|
+
require_relative './sw_characters/character.rb'
|
4
|
+
require_relative './sw_characters/api.rb'
|
5
|
+
require_relative './sw_characters/planet.rb'
|
6
|
+
require_relative './sw_characters/film.rb'
|
7
|
+
require_relative './sw_characters/species.rb'
|
8
|
+
require 'open-uri'
|
9
|
+
require 'nokogiri'
|
@@ -0,0 +1,88 @@
|
|
1
|
+
require 'open-uri'
|
2
|
+
require 'nokogiri'
|
3
|
+
require 'json'
|
4
|
+
|
5
|
+
class SwCharacters::API
|
6
|
+
|
7
|
+
def self.load_characters
|
8
|
+
puts "Loading Characters..."
|
9
|
+
y = 1
|
10
|
+
x = 1
|
11
|
+
until y == SwCharacters::Character.all.length
|
12
|
+
data = open("https://swapi.co/api/people/?page=#{x}&format=json").read
|
13
|
+
my_hash = JSON.parse(data)
|
14
|
+
y = my_hash['count'].to_i
|
15
|
+
print "#{SwCharacters::Character.all.length}..."
|
16
|
+
people = my_hash['results']
|
17
|
+
people.each do |person|
|
18
|
+
if person['species'].length == 0
|
19
|
+
species_hash = {'1' => 'unknown'}
|
20
|
+
else
|
21
|
+
species_hash = SwCharacters::Species.all.select do |key, value|
|
22
|
+
key == person['species'].first.split('/').last
|
23
|
+
end
|
24
|
+
end
|
25
|
+
planet_hash = SwCharacters::Planet.all.select do |key, value|
|
26
|
+
key == person['homeworld'].split('/').last
|
27
|
+
end
|
28
|
+
film_ids = person['films'].map {|film_url| film_url.split('/').last}
|
29
|
+
film_hashes = SwCharacters::Film.all.select do |film_id, film|
|
30
|
+
film_ids.include?(film.film_id)
|
31
|
+
end
|
32
|
+
films = film_hashes.map {|key, value| value}
|
33
|
+
SwCharacters::Character.new(person['name'], planet_hash.values[0], films, species_hash.values[0], person['url'].split('/').last)
|
34
|
+
end
|
35
|
+
x += 1
|
36
|
+
end
|
37
|
+
puts "#{SwCharacters::Character.all.length} Characters Loaded"
|
38
|
+
end
|
39
|
+
|
40
|
+
def self.load_planets
|
41
|
+
print "Loading Planets..."
|
42
|
+
y = 1
|
43
|
+
x = 1
|
44
|
+
until y == SwCharacters::Planet.all.length
|
45
|
+
data = open("https://swapi.co/api/planets/?page=#{x}&format=json").read
|
46
|
+
my_hash = JSON.parse(data)
|
47
|
+
y = my_hash['count'].to_i
|
48
|
+
planets = my_hash['results']
|
49
|
+
planets.each do |planet|
|
50
|
+
id = planet['url'].split('/').last
|
51
|
+
SwCharacters::Planet.new(planet['name'], id, planet['climate'], planet['terrain'])
|
52
|
+
end
|
53
|
+
x += 1
|
54
|
+
end
|
55
|
+
puts "Planets Loaded"
|
56
|
+
end
|
57
|
+
|
58
|
+
def self.load_films
|
59
|
+
print "Loading Films..."
|
60
|
+
data = open("https://swapi.co/api/films/?format=json").read
|
61
|
+
my_hash = JSON.parse(data)
|
62
|
+
films = my_hash['results']
|
63
|
+
films.each do |film|
|
64
|
+
id = film['url'].split('/').last
|
65
|
+
SwCharacters::Film.new(film['title'],film['opening_crawl'],film['director'],film['release_date'], id)
|
66
|
+
end
|
67
|
+
puts "Films Loaded"
|
68
|
+
end
|
69
|
+
|
70
|
+
def self.load_species
|
71
|
+
print "Loading Species..."
|
72
|
+
y = 1
|
73
|
+
x = 1
|
74
|
+
until y == SwCharacters::Species.all.length
|
75
|
+
data = open("https://swapi.co/api/species/?page=#{x}&format=json").read
|
76
|
+
my_hash = JSON.parse(data)
|
77
|
+
y = my_hash['count'].to_i
|
78
|
+
species = my_hash['results']
|
79
|
+
species.each do |species|
|
80
|
+
id = species['url'].split('/').last
|
81
|
+
SwCharacters::Species.new(species['name'],species['classification'],species['language'], id)
|
82
|
+
end
|
83
|
+
x += 1
|
84
|
+
end
|
85
|
+
puts "Species loaded"
|
86
|
+
end
|
87
|
+
|
88
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
class SwCharacters::Character
|
2
|
+
|
3
|
+
attr_accessor :name, :homeworld, :films, :species, :character_id
|
4
|
+
|
5
|
+
@@all = {}
|
6
|
+
|
7
|
+
def initialize(name, homeworld, films, species, character_id)
|
8
|
+
self.name = name
|
9
|
+
self.homeworld = homeworld
|
10
|
+
self.films = films
|
11
|
+
self.species = species
|
12
|
+
self.character_id = character_id
|
13
|
+
self.class.all[character_id] = self
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.all
|
17
|
+
@@all
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
@@ -0,0 +1,215 @@
|
|
1
|
+
require 'pry'
|
2
|
+
|
3
|
+
|
4
|
+
class SwCharacters::CLI
|
5
|
+
|
6
|
+
def run
|
7
|
+
puts ""
|
8
|
+
puts "
|
9
|
+
██╗ ██╗███████╗██╗ ██████╗ ██████╗ ███╗ ███╗███████╗
|
10
|
+
██║ ██║██╔════╝██║ ██╔════╝██╔═══██╗████╗ ████║██╔════╝
|
11
|
+
██║ █╗ ██║█████╗ ██║ ██║ ██║ ██║██╔████╔██║█████╗
|
12
|
+
██║███╗██║██╔══╝ ██║ ██║ ██║ ██║██║╚██╔╝██║██╔══╝
|
13
|
+
╚███╔███╔╝███████╗███████╗╚██████╗╚██████╔╝██║ ╚═╝ ██║███████╗
|
14
|
+
╚══╝╚══╝ ╚══════╝╚══════╝ ╚═════╝ ╚═════╝ ╚═╝ ╚═╝╚══════╝
|
15
|
+
|
16
|
+
"
|
17
|
+
puts "Welcome to the Star Wars Character Database!"
|
18
|
+
puts ""
|
19
|
+
SwCharacters::API.load_planets
|
20
|
+
SwCharacters::API.load_films
|
21
|
+
SwCharacters::API.load_species
|
22
|
+
SwCharacters::API.load_characters
|
23
|
+
|
24
|
+
self.menu
|
25
|
+
end
|
26
|
+
|
27
|
+
def menu
|
28
|
+
puts ""
|
29
|
+
puts "1. List all Characters"
|
30
|
+
puts "2. List all Planets"
|
31
|
+
puts "3. List all Films"
|
32
|
+
puts "4. List all Species"
|
33
|
+
puts "5. Search Characters by name"
|
34
|
+
puts "exit: Exits the program"
|
35
|
+
# run while @input != "exit"
|
36
|
+
input = gets.strip
|
37
|
+
case input
|
38
|
+
when '1'
|
39
|
+
self.list_characters
|
40
|
+
when '2'
|
41
|
+
self.list_planets
|
42
|
+
when '3'
|
43
|
+
self.list_films
|
44
|
+
when '4'
|
45
|
+
self.list_species
|
46
|
+
when '5'
|
47
|
+
self.search_characters
|
48
|
+
when 'exit'
|
49
|
+
puts "Thank you for using the Star Wars Character Database!"
|
50
|
+
puts "May the Force be with you!"
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
def return_to_menu
|
55
|
+
puts ""
|
56
|
+
puts "Type 1 to return to the main menu"
|
57
|
+
input = gets.chomp
|
58
|
+
input == '1' ? self.menu : nil
|
59
|
+
end
|
60
|
+
|
61
|
+
|
62
|
+
def list_characters
|
63
|
+
puts ""
|
64
|
+
sorted = SwCharacters::Character.all.sort_by {|id, character| id.to_i}
|
65
|
+
sorted.each do |character|
|
66
|
+
puts "#{character[0]}. #{character[1].name}"
|
67
|
+
end
|
68
|
+
puts "Select a character number or type menu for main menu"
|
69
|
+
input = gets.chomp
|
70
|
+
if SwCharacters::Character.all.keys.include?(input)
|
71
|
+
self.display_character(input)
|
72
|
+
elsif input == 'menu'
|
73
|
+
self.menu
|
74
|
+
else
|
75
|
+
'Invalid input'
|
76
|
+
self.list_characters
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
def display_character(input)
|
81
|
+
puts ""
|
82
|
+
puts "#{SwCharacters::Character.all[input].name}"
|
83
|
+
puts "Homeworld: #{SwCharacters::Character.all[input].homeworld.name}"
|
84
|
+
if SwCharacters::Character.all[input].species == 'unknown'
|
85
|
+
puts "Species: unknown"
|
86
|
+
else
|
87
|
+
puts "Species: #{SwCharacters::Character.all[input].species.name}"
|
88
|
+
end
|
89
|
+
puts "Films:"
|
90
|
+
puts ""
|
91
|
+
SwCharacters::Character.all[input].films.each {|film| puts "#{film.title}"}
|
92
|
+
self.return_to_menu
|
93
|
+
end
|
94
|
+
|
95
|
+
def list_planets
|
96
|
+
puts ""
|
97
|
+
sorted = SwCharacters::Planet.all.sort_by {|id, planet| id.to_i}
|
98
|
+
sorted.each do |planet|
|
99
|
+
puts "#{planet[0]}. #{planet[1].name}"
|
100
|
+
end
|
101
|
+
puts "Select a planet number or type menu for main menu"
|
102
|
+
input = gets.chomp
|
103
|
+
if input == 'menu'
|
104
|
+
self.menu
|
105
|
+
elsif (SwCharacters::Planet.all.keys).include?(input)
|
106
|
+
self.display_planet(input)
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
def display_planet(input)
|
111
|
+
puts ""
|
112
|
+
puts "#{SwCharacters::Planet.all[input].name}"
|
113
|
+
puts "Climate: #{SwCharacters::Planet.all[input].climate}"
|
114
|
+
puts "Terrain: #{SwCharacters::Planet.all[input].terrain}"
|
115
|
+
puts "Natives:"
|
116
|
+
SwCharacters::Character.all.each do |id, character|
|
117
|
+
if character.homeworld.name == SwCharacters::Planet.all[input].name
|
118
|
+
puts "#{character.name}"
|
119
|
+
end
|
120
|
+
end
|
121
|
+
self.return_to_menu
|
122
|
+
end
|
123
|
+
|
124
|
+
def list_films
|
125
|
+
puts ""
|
126
|
+
sorted = SwCharacters::Film.all.sort_by {|id, planet| id.to_i}
|
127
|
+
sorted.each do |film|
|
128
|
+
puts "#{film[0]}. #{film[1].title}"
|
129
|
+
end
|
130
|
+
puts "Select a film number or type menu for main menu"
|
131
|
+
input = gets.chomp
|
132
|
+
if input == 'menu'
|
133
|
+
self.menu
|
134
|
+
elsif (SwCharacters::Film.all.keys).include?(input)
|
135
|
+
self.display_film(input)
|
136
|
+
end
|
137
|
+
end
|
138
|
+
|
139
|
+
def display_film(input)
|
140
|
+
puts ""
|
141
|
+
puts "Title: #{SwCharacters::Film.all[input].title}"
|
142
|
+
puts "Director: #{SwCharacters::Film.all[input].director}"
|
143
|
+
puts "Release Date: #{SwCharacters::Film.all[input].release_date}"
|
144
|
+
puts "Opening Crawl:"
|
145
|
+
puts ""
|
146
|
+
puts "#{SwCharacters::Film.all[input].opening_crawl.strip}"
|
147
|
+
self.return_to_menu
|
148
|
+
end
|
149
|
+
|
150
|
+
def list_species
|
151
|
+
puts ""
|
152
|
+
sorted = SwCharacters::Species.all.sort_by {|id, species| id.to_i}
|
153
|
+
sorted.each do |species|
|
154
|
+
puts "#{species[0]}. #{species[1].name}"
|
155
|
+
end
|
156
|
+
puts ""
|
157
|
+
puts "Select a species number or type menu for main menu"
|
158
|
+
input = gets.chomp
|
159
|
+
if input == 'menu'
|
160
|
+
self.menu
|
161
|
+
elsif (SwCharacters::Species.all.keys).include?(input)
|
162
|
+
self.display_species(input)
|
163
|
+
end
|
164
|
+
end
|
165
|
+
|
166
|
+
def display_species(input)
|
167
|
+
puts ""
|
168
|
+
puts "Name: #{SwCharacters::Species.all[input].name}"
|
169
|
+
puts "Classification: #{SwCharacters::Species.all[input].classification}"
|
170
|
+
puts "Language: #{SwCharacters::Species.all[input].language}"
|
171
|
+
puts "Example Characters:"
|
172
|
+
puts ""
|
173
|
+
SwCharacters::Character.all.each do |id, character|
|
174
|
+
if character.species != 'unknown'
|
175
|
+
if character.species.name == SwCharacters::Species.all[input].name
|
176
|
+
puts "#{character.name}"
|
177
|
+
end
|
178
|
+
end
|
179
|
+
end
|
180
|
+
self.return_to_menu
|
181
|
+
end
|
182
|
+
|
183
|
+
def search_characters
|
184
|
+
puts ''
|
185
|
+
puts 'Please type the name of a character'
|
186
|
+
puts 'For best results, type only one part of their name and omit titles like "General"'
|
187
|
+
input = gets.chomp
|
188
|
+
results = SwCharacters::Character.all.select do |id, character|
|
189
|
+
character.name.include?(input)
|
190
|
+
end
|
191
|
+
if results.length == 0
|
192
|
+
puts ""
|
193
|
+
"No results, please try another search"
|
194
|
+
self.search_characters
|
195
|
+
elsif results.length == 1
|
196
|
+
self.display_character(results.values.first.character_id)
|
197
|
+
else
|
198
|
+
self.display_results(results)
|
199
|
+
end
|
200
|
+
end
|
201
|
+
|
202
|
+
def display_results(results)
|
203
|
+
puts ""
|
204
|
+
results.each {|index, character| puts "#{index}. #{character.name}"}
|
205
|
+
puts ''
|
206
|
+
puts "Please type the number of the entry you were searching for or type search to try again."
|
207
|
+
input= gets.chomp
|
208
|
+
if input == 'search'
|
209
|
+
self.search_characters
|
210
|
+
elsif results.keys.include?(input)
|
211
|
+
self.display_character(results[input].character_id)
|
212
|
+
end
|
213
|
+
end
|
214
|
+
|
215
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
class SwCharacters::Film
|
2
|
+
attr_accessor :title, :opening_crawl, :director, :release_date, :film_id
|
3
|
+
@@all = {}
|
4
|
+
|
5
|
+
def initialize(title, opening_crawl, director, release_date, id)
|
6
|
+
self.title = title
|
7
|
+
self.opening_crawl = opening_crawl
|
8
|
+
self.director = director
|
9
|
+
self.release_date = release_date
|
10
|
+
self.film_id = id
|
11
|
+
self.class.all[self.film_id] = self
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.all
|
15
|
+
@@all
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
class SwCharacters::Planet
|
2
|
+
attr_accessor :name, :planet_id, :climate, :terrain
|
3
|
+
@@all = {}
|
4
|
+
|
5
|
+
def initialize(name, id, climate, terrain)
|
6
|
+
self.name = name
|
7
|
+
self.planet_id = id
|
8
|
+
self.climate = climate
|
9
|
+
self.terrain = terrain
|
10
|
+
self.class.all[self.planet_id] = self
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.all
|
14
|
+
@@all
|
15
|
+
end
|
16
|
+
|
17
|
+
|
18
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
class SwCharacters::Species
|
2
|
+
attr_accessor :name, :classification, :language, :species_id
|
3
|
+
@@all = {}
|
4
|
+
|
5
|
+
def initialize(name, classification, language, id)
|
6
|
+
self.name = name
|
7
|
+
self.classification = classification
|
8
|
+
self.language = language
|
9
|
+
self.species_id = id
|
10
|
+
self.class.all[self.species_id] = self
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.all
|
14
|
+
@@all
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
|
2
|
+
lib = File.expand_path("../lib", __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require "sw_characters/version"
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "sw_characters"
|
8
|
+
spec.version = SwCharacters::VERSION
|
9
|
+
spec.authors = ["Matthew McCormack"]
|
10
|
+
spec.email = ["mmccormack1182@gmail.com"]
|
11
|
+
|
12
|
+
spec.summary = "An API built encyclopedia of characters, planets, species, and films from the Star Wars Universe."
|
13
|
+
spec.description = "An encyclopedia of all named characters in the Star Wars Movies, including their species, fims, and homeworlds. You can manually look through each list or search spefic characters by their name."
|
14
|
+
spec.homepage = "http://www.github.com/mlmccor/sw_characters"
|
15
|
+
|
16
|
+
# Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
|
17
|
+
# to allow pushing to a single host or delete this section to allow pushing to any host.
|
18
|
+
if spec.respond_to?(:metadata)
|
19
|
+
spec.metadata["allowed_push_host"] = "https://www.rubygems.org"
|
20
|
+
else
|
21
|
+
raise "RubyGems 2.0 or newer is required to protect against " \
|
22
|
+
"public gem pushes."
|
23
|
+
end
|
24
|
+
|
25
|
+
# Specify which files should be added to the gem when it is released.
|
26
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
27
|
+
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
28
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
29
|
+
end
|
30
|
+
# spec.bindir = "exe"
|
31
|
+
spec.executables = ["sw_characters"]
|
32
|
+
spec.require_paths = ["lib"]
|
33
|
+
|
34
|
+
spec.add_development_dependency "bundler", "~> 1.16"
|
35
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
36
|
+
|
37
|
+
spec.license = 'MIT'
|
38
|
+
|
39
|
+
end
|
metadata
ADDED
@@ -0,0 +1,93 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: sw_characters
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.4.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Matthew McCormack
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2019-10-31 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
|
+
description: An encyclopedia of all named characters in the Star Wars Movies, including
|
42
|
+
their species, fims, and homeworlds. You can manually look through each list or
|
43
|
+
search spefic characters by their name.
|
44
|
+
email:
|
45
|
+
- mmccormack1182@gmail.com
|
46
|
+
executables:
|
47
|
+
- sw_characters
|
48
|
+
extensions: []
|
49
|
+
extra_rdoc_files: []
|
50
|
+
files:
|
51
|
+
- CODE_OF_CONDUCT.md
|
52
|
+
- Gemfile
|
53
|
+
- LICENSE.txt
|
54
|
+
- README.md
|
55
|
+
- Rakefile
|
56
|
+
- bin/console
|
57
|
+
- bin/setup
|
58
|
+
- bin/sw_characters
|
59
|
+
- lib/sw_characters.rb
|
60
|
+
- lib/sw_characters/api.rb
|
61
|
+
- lib/sw_characters/character.rb
|
62
|
+
- lib/sw_characters/cli.rb
|
63
|
+
- lib/sw_characters/film.rb
|
64
|
+
- lib/sw_characters/planet.rb
|
65
|
+
- lib/sw_characters/species.rb
|
66
|
+
- lib/sw_characters/version.rb
|
67
|
+
- sw_characters.gemspec
|
68
|
+
homepage: http://www.github.com/mlmccor/sw_characters
|
69
|
+
licenses:
|
70
|
+
- MIT
|
71
|
+
metadata:
|
72
|
+
allowed_push_host: https://www.rubygems.org
|
73
|
+
post_install_message:
|
74
|
+
rdoc_options: []
|
75
|
+
require_paths:
|
76
|
+
- lib
|
77
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
78
|
+
requirements:
|
79
|
+
- - ">="
|
80
|
+
- !ruby/object:Gem::Version
|
81
|
+
version: '0'
|
82
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
83
|
+
requirements:
|
84
|
+
- - ">="
|
85
|
+
- !ruby/object:Gem::Version
|
86
|
+
version: '0'
|
87
|
+
requirements: []
|
88
|
+
rubygems_version: 3.0.6
|
89
|
+
signing_key:
|
90
|
+
specification_version: 4
|
91
|
+
summary: An API built encyclopedia of characters, planets, species, and films from
|
92
|
+
the Star Wars Universe.
|
93
|
+
test_files: []
|