Class: Spaceship::Client::UserInterface
- Inherits:
-
Object
- Object
- Spaceship::Client::UserInterface
- Defined in:
- lib/spaceship/ui.rb,
lib/spaceship/ui/select_team.rb
Overview
All User Interface related code lives in this class
Instance Method Summary collapse
-
#client ⇒ Object
Access the client this UserInterface object is for.
-
#initialize(c) ⇒ UserInterface
constructor
Is called by the client to generate one instance of UserInterface.
-
#select_team ⇒ Object
Shows the UI to select a team.
Constructor Details
#initialize(c) ⇒ UserInterface
Is called by the client to generate one instance of UserInterface
18 19 20 |
# File 'lib/spaceship/ui.rb', line 18 def initialize(c) @client = c end |
Instance Method Details
#client ⇒ Object
Access the client this UserInterface object is for
23 24 25 |
# File 'lib/spaceship/ui.rb', line 23 def client @client end |
#select_team ⇒ Object
Shows the UI to select a team
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/spaceship/ui/select_team.rb', line 34 def select_team teams = client.teams raise "Your account is in no teams" if teams.count == 0 return teams[0]['teamId'] if teams.count == 1 # user is just in one team loop do # Multiple teams, user has to select puts "Multiple teams found, please enter the number of the team you want to use: ".yellow teams.each_with_index do |team, i| puts "#{i + 1}) #{team['teamId']} #{team['name']} (#{team['type']})".green end selected = $stdin.gets.strip.to_i - 1 team_to_use = teams[selected] if selected >= 0 return team_to_use['teamId'] if team_to_use end end |