Class: KiPivotal::Interactive
- Inherits:
-
Object
- Object
- KiPivotal::Interactive
- Defined in:
- lib/ki_pivotal/interactive.rb
Class Method Summary collapse
- .choose_from_many(things, question) ⇒ Object
- .new_story ⇒ Object
-
.repeatedly_ask(question) ⇒ Object
“Resistance is futile!”, “We will get an answer!”.
-
.repeatedly_choose_from(things, question) ⇒ Object
“We have ways of making you talk!”.
- .select_project(prompt) ⇒ Object
- .select_story(project_id, prompt) ⇒ Object
- .simple_query(prompt) ⇒ Object
Class Method Details
.choose_from_many(things, question) ⇒ Object
21 22 23 24 25 26 27 28 |
# File 'lib/ki_pivotal/interactive.rb', line 21 def self.choose_from_many(things, question) $stderr.puts "\n "+question things.each_with_index { |thing, index| $stderr.puts " #{index+1} ".green + " #{thing}" } index = ( (simple_query( "Enter an index (#{(1..things.size)})" ).to_i) - 1 ) index = ( index >= 0 && index < things.size ) ? index : nil end |
.new_story ⇒ Object
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/ki_pivotal/interactive.rb', line 68 def self.new_story name = repeatedly_ask("Name of story") description = repeatedly_ask("Description of story") types = ["bug","feature","release","chore"] type = types[repeatedly_choose_from(types, "What type of story is this?")] { name: name, description: description, story_type: type, requested_by: 'Kiseru', ki_type: 'pivotal_story' }.to_json end |
.repeatedly_ask(question) ⇒ Object
“Resistance is futile!”, “We will get an answer!”
5 6 7 8 9 10 11 |
# File 'lib/ki_pivotal/interactive.rb', line 5 def self.repeatedly_ask(question) response = "" while response == "" response = simple_query(question) end response end |
.repeatedly_choose_from(things, question) ⇒ Object
“We have ways of making you talk!”
13 14 15 16 17 18 19 |
# File 'lib/ki_pivotal/interactive.rb', line 13 def self.repeatedly_choose_from(things, question) index = nil while index.nil? index = choose_from_many(things, question) end index end |
.select_project(prompt) ⇒ Object
55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/ki_pivotal/interactive.rb', line 55 def self.select_project(prompt) projects = MultiJson.load(KiPivotal::Api.new.projects) if projects.size > 1 index = repeatedly_choose_from(projects.map { |p| p['name'] }, prompt) else index = 0 end $stderr.puts "\n Chosen project is '#{projects[index]['name']}' (#{projects[index]['id']})" projects[index]['id'] end |
.select_story(project_id, prompt) ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/ki_pivotal/interactive.rb', line 39 def self.select_story(project_id, prompt) limit = 20 stories = MultiJson.load(KiPivotal::Api.new.stories_in_project(project_id)) stories = stories.reject { |story| %w{accepted unscheduled}.member? story['current_state'] }[0,20] if stories.size > 1 index = repeatedly_choose_from(stories.map { |p| p['name'] }, prompt) else index = 0 end $stderr.puts "\n Chosen story is '#{stories[index]['name']}' (#{stories[index]['id']})" stories[index]['id'] end |
.simple_query(prompt) ⇒ Object
30 31 32 33 34 35 36 37 |
# File 'lib/ki_pivotal/interactive.rb', line 30 def self.simple_query(prompt) if prompt.nil? $stderr.print "\n> " else $stderr.print "\n #{prompt}: " end $stdin.gets.chomp end |