star_wars_finder 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: a9e4c32db2faf9f5105ea59f77fc959daf47a0ef223a575413dd6a4aa6bca8f6
4
+ data.tar.gz: 5e97001dc9d30487107f166202ab56b3f9311f122b663ef9d8cd94872425032c
5
+ SHA512:
6
+ metadata.gz: 1e8b96c3f2e86d822f5651a183cb7b91706c2f79b8ff4d568ce904ad9fbe3d73d8b3588a3fdbe6f2e4cd4576f50c187140fd531b977d9f001779df610f39197b
7
+ data.tar.gz: be330739c84f09d7d3d59ad2271710020ce957af50c68ec53faa6b5f9a6e420253a04e98c8d70967c8fbde2159a45052cf2f4e01b6d8a6988d9e42c370b7bb4b
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
@@ -0,0 +1,6 @@
1
+ ---
2
+ language: ruby
3
+ cache: bundler
4
+ rvm:
5
+ - 2.6.5
6
+ before_install: gem install bundler -v 2.1.4
@@ -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 tyler-w-jones@hotmail.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
@@ -0,0 +1,11 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in star_wars_finder.gemspec
4
+ gemspec
5
+
6
+ gem "rake", "~> 12.0"
7
+ gem "rspec", "~> 3.0"
8
+ gem "bundler", "~> 2.1.4"
9
+ gem 'pry', '~> 0.13.0'
10
+ gem 'httparty', '~> 0.18.0'
11
+ gem 'require_all', '~> 3.0'
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2020 RTEYL
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.
@@ -0,0 +1,49 @@
1
+ # StarWarsFinder
2
+
3
+ Welcome to Welcome to my Star Wars Finder gem. Using an API to collect character data you will be able to seach for a Star Wars character and get information about it. At this moment a character is only searchable by name however later updates will include search by planets and search by species.
4
+
5
+ ## Installation
6
+ Fork/Clone this lab
7
+
8
+ Then execute:
9
+
10
+ $ bin/run
11
+
12
+ ** gem has not been published to rubygems at this moment **
13
+
14
+ Add this line to your application's Gemfile:
15
+
16
+ ```ruby
17
+ gem 'star_wars_finder'
18
+ ```
19
+
20
+ And then execute:
21
+
22
+ $ bundle install
23
+
24
+ Or install it yourself as:
25
+
26
+ $ gem install star_wars_finder
27
+
28
+ ## Usage
29
+
30
+ Put `bin/run` in the command line and you'll be prompted with some top character choices to search by or enter your own search term. The search input is dynamic in that your term doesn't need to exactly match a characters name `chew => Chewbacca`, `luke => Luke Skywalker` etc..
31
+
32
+ ## Development
33
+
34
+ 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.
35
+
36
+ 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).
37
+
38
+ ## Contributing
39
+
40
+ Bug reports and pull requests are welcome on GitHub at https://github.com/RTEYL/star_wars_finder. 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/RTEYL/star_wars_finder/blob/master/CODE_OF_CONDUCT.md).
41
+
42
+
43
+ ## License
44
+
45
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
46
+
47
+ ## Code of Conduct
48
+
49
+ Everyone interacting in the StarWarsFinder project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/RTEYL/star_wars_finder/blob/master/CODE_OF_CONDUCT.md).
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1 @@
1
+ theme: jekyll-theme-slate
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "star_wars_finder"
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/run ADDED
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env ruby
2
+ require_relative '../config/environment'
3
+ API.get_characters
4
+ CLI.start
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,4 @@
1
+ require 'pry'
2
+ require 'httparty'
3
+ require 'require_all'
4
+ require_all './lib'
@@ -0,0 +1,30 @@
1
+ class API
2
+ def self.get_characters
3
+ puts "\nLoading...\n\n"
4
+ people = Array.new
5
+ i = 1
6
+ while i < 10 do
7
+ response = HTTParty.get("http://swapi.co/api/people/?page=#{i}")
8
+ response["results"].each{|obj| people << obj}
9
+ i+=1
10
+ end
11
+ self.create_people_objects(people)
12
+ end
13
+ def self.create_people_objects(people)
14
+ people.each {|hash| hash["name"] = Character.new(hash)}
15
+ end
16
+ def self.create_species(species)
17
+ if species.class == String
18
+ species.gsub!("https", "http")
19
+ response = HTTParty.get("#{species}")
20
+ response["name"] = Species.new(response)
21
+ end
22
+ end
23
+ def self.create_homeworld(planet)
24
+ if planet.class == String
25
+ planet.gsub!("https", "http")
26
+ response = HTTParty.get("#{planet}")
27
+ response["name"] = Planet.new(response)
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,55 @@
1
+ class Character
2
+ attr_reader :name, :height, :mass, :hair_color, :eye_color, :birth_year, :species, :homeworld
3
+ @@all = Array.new
4
+ def initialize(p_hash)
5
+ p_hash.each do |key, value|
6
+ if self.class.instance_methods.include?(key.to_sym)
7
+ self.instance_variable_set("@#{key}", value)
8
+ end
9
+ end
10
+ @@all << self
11
+ end
12
+ def self.all
13
+ @@all
14
+ end
15
+ def self.top_10
16
+ top_10_arr =
17
+ ["Chewbacca", "C-3PO", "R2-D2", "Palpatine", "Obi-Wan Kenobi", "Luke Skywalker", "Leia", "Yoda", "Han Solo", "Darth Vader"]
18
+ top_10_arr.sort.each { |person| puts "#{person}" }
19
+ end
20
+ def self.has_name?(name)
21
+ self.all.each do |person|
22
+ if person.name.downcase.match?(name)
23
+ CLI.display_search_res(person)
24
+ else false
25
+ end
26
+ end
27
+ end
28
+ def mass
29
+ mass = @mass.to_i * 2.205
30
+ "#{mass.round(2).to_i} lbs."
31
+ end
32
+ def height
33
+ feet = (@height.to_i/2.54)/12
34
+ inch = feet.remainder(1) * 12
35
+ "#{feet.to_i} ft. #{inch.round} in."
36
+ end
37
+ def species
38
+ if @species.class == Species
39
+ @species.name
40
+ elsif @species != []
41
+ @species = API.create_species(@species[0])
42
+ @species.name
43
+ else
44
+ @species = "unknown"
45
+ end
46
+ end
47
+ def homeworld
48
+ if @homeworld.class != Planet
49
+ @homeworld = API.create_homeworld(@homeworld)
50
+ @homeworld.name
51
+ else
52
+ @homeworld.name
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,46 @@
1
+ class CLI
2
+ def self.start
3
+ self.welcome
4
+ self.display_characters
5
+ end
6
+ def self.welcome
7
+ puts "Welcome to my Star Wars Gem! \n\n"
8
+ sleep(2)
9
+ puts "You will be able to see a list of characters and some info about them\n\n"
10
+ end
11
+ def self.display_characters
12
+ Character.top_10
13
+ puts "\nSelect a character in this top 10 list or,\nsearch for a character by name"
14
+ puts "Type 'exit' to exit\n\n"
15
+ name = gets.strip.downcase
16
+ if name == "exit"
17
+ exit!
18
+ elsif Character.has_name?(name) == false && name.to_i == 0.0
19
+ puts "The name you listed is not available"
20
+ sleep(1.25)
21
+ self.display_characters
22
+ else
23
+ puts "Entry is not valid"
24
+ sleep(1.25)
25
+ self.display_characters
26
+ end
27
+ end
28
+ def self.display_search_res(character)
29
+ character.instance_variables.each.with_index do |m,i|
30
+ puts "#{character.instance_variables[i].to_s.gsub("@", "")}: #{character.send(m.to_s.gsub("@", ""))}"
31
+ end
32
+ self.exit?
33
+ end
34
+ def self.exit?
35
+ puts "\nSearch again? y/n"
36
+ input = gets.strip.downcase
37
+ if input == 'y'
38
+ self.display_characters
39
+ elsif input != 'n'
40
+ puts "invalid choice"
41
+ self.exit?
42
+ else
43
+ exit!
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,8 @@
1
+ class Planet
2
+ attr_reader :name, :terrain, :population
3
+ def initialize(planet)
4
+ @name = planet["name"]
5
+ @terrain = planet["terrain"]
6
+ @population = planet["population"]
7
+ end
8
+ end
@@ -0,0 +1,8 @@
1
+ class Species
2
+ attr_reader :name, :classification, :average_lifespan
3
+ def initialize(species)
4
+ @name = species["name"]
5
+ @classification = species["classification"]
6
+ @average_lifespan = species["average_lifespan"]
7
+ end
8
+ end
@@ -0,0 +1,3 @@
1
+ module StarWarsFinder
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,35 @@
1
+ require_relative 'lib/star_wars_finder/version'
2
+
3
+ Gem::Specification.new do |spec|
4
+ spec.name = "star_wars_finder"
5
+ spec.version = StarWarsFinder::VERSION
6
+ spec.authors = ["RTEYL"]
7
+ spec.email = ["rteyl1690@gmail.com"]
8
+
9
+ spec.summary = %q{CLI to seach for a Star Wars character and get information about it.}
10
+ spec.description = %q{Using an API to collect character data you will be able to seach for a Star Wars character and get information about it. At this moment a character is only searchable by name however later updates will include search by planets and search by species.}
11
+ spec.homepage = "https://github.com/RTEYL/star_wars_finder"
12
+ spec.license = "MIT"
13
+ spec.required_ruby_version = Gem::Requirement.new(">= 2.3.0")
14
+
15
+ # spec.metadata["allowed_push_host"] = "TODO: Set to 'http://mygemserver.com'"
16
+
17
+ spec.metadata["homepage_uri"] = spec.homepage
18
+ spec.metadata["source_code_uri"] = "https://github.com/RTEYL/star_wars_finder"
19
+ # spec.metadata["changelog_uri"] = "TODO: Put your gem's CHANGELOG.md URL here."
20
+
21
+ # Specify which files should be added to the gem when it is released.
22
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
23
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
24
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
25
+ end
26
+ spec.bindir = "bin"
27
+ spec.executables = ["run"]
28
+ spec.require_paths = ["lib"]
29
+
30
+ spec.add_development_dependency "rake", "~> 12.0"
31
+ spec.add_development_dependency "bundler", "~> 2.1.4"
32
+ spec.add_development_dependency 'pry', '~> 0.13.0'
33
+ spec.add_development_dependency 'require_all', '~> 3.0'
34
+ spec.add_dependency 'httparty', '~> 0.18.0'
35
+ end
metadata ADDED
@@ -0,0 +1,139 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: star_wars_finder
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - RTEYL
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2020-04-01 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rake
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '12.0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '12.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 2.1.4
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 2.1.4
41
+ - !ruby/object:Gem::Dependency
42
+ name: pry
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 0.13.0
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 0.13.0
55
+ - !ruby/object:Gem::Dependency
56
+ name: require_all
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '3.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '3.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: httparty
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: 0.18.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.18.0
83
+ description: Using an API to collect character data you will be able to seach for
84
+ a Star Wars character and get information about it. At this moment a character is
85
+ only searchable by name however later updates will include search by planets and
86
+ search by species.
87
+ email:
88
+ - rteyl1690@gmail.com
89
+ executables:
90
+ - run
91
+ extensions: []
92
+ extra_rdoc_files: []
93
+ files:
94
+ - ".gitignore"
95
+ - ".rspec"
96
+ - ".travis.yml"
97
+ - CODE_OF_CONDUCT.md
98
+ - Gemfile
99
+ - LICENSE.txt
100
+ - README.md
101
+ - Rakefile
102
+ - _config.yml
103
+ - bin/console
104
+ - bin/run
105
+ - bin/setup
106
+ - config/environment.rb
107
+ - lib/star_wars_finder/api.rb
108
+ - lib/star_wars_finder/character.rb
109
+ - lib/star_wars_finder/cli.rb
110
+ - lib/star_wars_finder/planet.rb
111
+ - lib/star_wars_finder/species.rb
112
+ - lib/star_wars_finder/version.rb
113
+ - star_wars_finder.gemspec
114
+ homepage: https://github.com/RTEYL/star_wars_finder
115
+ licenses:
116
+ - MIT
117
+ metadata:
118
+ homepage_uri: https://github.com/RTEYL/star_wars_finder
119
+ source_code_uri: https://github.com/RTEYL/star_wars_finder
120
+ post_install_message:
121
+ rdoc_options: []
122
+ require_paths:
123
+ - lib
124
+ required_ruby_version: !ruby/object:Gem::Requirement
125
+ requirements:
126
+ - - ">="
127
+ - !ruby/object:Gem::Version
128
+ version: 2.3.0
129
+ required_rubygems_version: !ruby/object:Gem::Requirement
130
+ requirements:
131
+ - - ">="
132
+ - !ruby/object:Gem::Version
133
+ version: '0'
134
+ requirements: []
135
+ rubygems_version: 3.0.3
136
+ signing_key:
137
+ specification_version: 4
138
+ summary: CLI to seach for a Star Wars character and get information about it.
139
+ test_files: []