welcome_to_hogwarts_cli 0.0.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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 903368356ac03784557ac87786a227f95fbd90ddfa689dafac6cca7685e3c3ee
4
+ data.tar.gz: c932a6234b39a0d8c818211eb9bdd6799acdcf8496e5b14490fa0d1f9dd614d4
5
+ SHA512:
6
+ metadata.gz: 423f2fc200de3d309438e6618eec672eacdce6eaa8ae3a9c2e32928937401c1fe1286bdf107f70b7656defd3eef22a046eb8ec1a223dba371055c9f6cc8651ca
7
+ data.tar.gz: 0f9982d211b22f7e7f43da4fe592b92acd00d98ec7f4c404c36aee374f295c05070237a58d34195c9d02fce36204c4761da5aa7fe2d111ac07c1a7965bdcd7d8
@@ -0,0 +1,23 @@
1
+ class API
2
+
3
+ BASE_URL = "https://www.potterapi.com/v1/houses?key="
4
+ KEY = ENV["API_KEY"]
5
+
6
+ def self.get_houses
7
+ uri = URI.parse("#{BASE_URL}#{KEY}")
8
+ response = Net::HTTP.get_response(uri)
9
+ data = JSON.parse(response.body)
10
+ data.each do |house|
11
+ name = house["name"]
12
+ colors = house["colors"].join(", ").capitalize
13
+ mascot = house["mascot"].capitalize
14
+ values = house["values"].join(", ").capitalize
15
+ head_of_house = house["headOfHouse"]
16
+ ghost = house["houseGhost"]
17
+ founder = house["founder"]
18
+ House.new(name, colors, mascot, values, head_of_house, ghost, founder)
19
+ end
20
+ end
21
+ end
22
+
23
+
@@ -0,0 +1,120 @@
1
+ class CLI
2
+
3
+ def run
4
+ API.get_houses
5
+ main
6
+ end
7
+
8
+ def main
9
+ puts "Welcome to Hogwarts, first-year!"
10
+ sleep 1
11
+ puts "To proceed to the Great Hall for the Sorting Ceremony, enter 'Let's go!'"
12
+ sleep 1
13
+ puts "To leave Hogwarts, enter 'Take me home!'"
14
+
15
+ input = gets.chomp
16
+
17
+ if input == "Let's go!"
18
+ sleep 1
19
+ sort
20
+ elsif input == "Take me home!"
21
+ sleep 1
22
+ early_exit
23
+ else
24
+ sleep 1
25
+ error
26
+ main
27
+ end
28
+ end
29
+
30
+ def sort
31
+ @@sorted_house = House.all.sample
32
+ print "You're in"
33
+ sleep 1
34
+ 3.times do
35
+ print "."
36
+ sleep 1
37
+ end
38
+ print "#{@@sorted_house.name}!" "\n"
39
+ sleep 2
40
+ more_house_info
41
+ end
42
+
43
+ def more_house_info
44
+ puts "Would you like more information on your house? Enter 'Yes' or 'No'."
45
+ input = gets.chomp
46
+ if input == 'Yes'
47
+ print_house_info(@@sorted_house)
48
+ another_house_info
49
+ elsif input == 'No'
50
+ sleep 1
51
+ another_house_info
52
+ else
53
+ sleep 1
54
+ error
55
+ more_house_info
56
+ end
57
+ end
58
+
59
+ def print_house_info(house)
60
+ sleep 1
61
+ puts "Founder: #{house.founder}"
62
+ sleep 1
63
+ puts "Colors: #{house.colors}"
64
+ sleep 1
65
+ puts "Mascot: #{house.mascot}"
66
+ sleep 1
67
+ puts "House Ghost: #{house.ghost}"
68
+ sleep 1
69
+ puts "Head of House: #{house.head_of_house}"
70
+ sleep 1
71
+ puts "Values: #{house.values}"
72
+ sleep 2
73
+ end
74
+
75
+ def another_house_info
76
+ puts "Would you like information on another house? Enter 'Yes' or 'No'."
77
+ input = gets.chomp
78
+ if input == 'Yes'
79
+ get_another_house_input
80
+ elsif input == 'No'
81
+ sleep 1
82
+ normal_exit
83
+ else
84
+ sleep 1
85
+ error
86
+ another_house_info
87
+ end
88
+ end
89
+
90
+ def get_another_house_input
91
+ puts "Please choose a house: Gryffindor, Hufflepuff, Ravenclaw, or Slytherin."
92
+ input = gets.chomp
93
+ if input == "Gryffindor" || input == "Hufflepuff" || input == "Ravenclaw" || input == "Slytherin"
94
+ house = House.all.find{|house| house.name == input}
95
+ print_house_info(house)
96
+ else
97
+ sleep 1
98
+ error
99
+ get_another_house_input
100
+ end
101
+ another_house_info
102
+ end
103
+
104
+ def early_exit
105
+ puts "We'll miss you this term. Enjoy your ride on the Hogwarts Express!"
106
+ exit
107
+ end
108
+
109
+ def normal_exit
110
+ puts "Have a great term, #{@@sorted_house.name}!"
111
+ exit
112
+ end
113
+
114
+ def error
115
+ puts "Sorry, we don't understand that muggle phrase."
116
+ sleep 2
117
+ end
118
+
119
+
120
+ end
@@ -0,0 +1,27 @@
1
+ class House
2
+ attr_accessor :name, :colors, :mascot, :values, :head_of_house, :ghost, :founder
3
+
4
+ @@all = []
5
+
6
+ def initialize(name, colors, mascot, values, head_of_house, ghost, founder)
7
+ @name = name
8
+ @colors = colors
9
+ @mascot = mascot
10
+ @values = values
11
+ @head_of_house = head_of_house
12
+ @ghost = ghost
13
+ @founder = founder
14
+ save
15
+ end
16
+
17
+ def self.all
18
+ @@all
19
+ end
20
+
21
+ def save
22
+ @@all << self
23
+ end
24
+
25
+ end
26
+
27
+
@@ -0,0 +1,10 @@
1
+ require 'bundler/setup'
2
+ Bundler.require(:default)
3
+ require 'open-uri'
4
+ require 'net/http'
5
+ require 'dotenv/load'
6
+
7
+ require_relative './hogwarts_cli/cli.rb'
8
+ require_relative './hogwarts_cli/api.rb'
9
+ require_relative './hogwarts_cli/hogwarts_houses.rb'
10
+
metadata ADDED
@@ -0,0 +1,48 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: welcome_to_hogwarts_cli
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Christine Zosche
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2020-06-07 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description:
14
+ email:
15
+ executables: []
16
+ extensions: []
17
+ extra_rdoc_files: []
18
+ files:
19
+ - lib/hogwarts_cli/api.rb
20
+ - lib/hogwarts_cli/cli.rb
21
+ - lib/hogwarts_cli/hogwarts_houses.rb
22
+ - lib/hogwarts_cli_environment.rb
23
+ homepage:
24
+ licenses:
25
+ - MIT
26
+ metadata: {}
27
+ post_install_message:
28
+ rdoc_options: []
29
+ require_paths:
30
+ - lib
31
+ - bin
32
+ required_ruby_version: !ruby/object:Gem::Requirement
33
+ requirements:
34
+ - - ">="
35
+ - !ruby/object:Gem::Version
36
+ version: '0'
37
+ required_rubygems_version: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - ">="
40
+ - !ruby/object:Gem::Version
41
+ version: '0'
42
+ requirements: []
43
+ rubygems_version: 3.0.8
44
+ signing_key:
45
+ specification_version: 4
46
+ summary: Sorts the user into their new house at Hogwarts and provides information
47
+ on the school's four houses
48
+ test_files: []