Class: Git2Mite::Gui
- Inherits:
-
Object
- Object
- Git2Mite::Gui
- Defined in:
- lib/git2mite/gui.rb
Instance Method Summary collapse
- #ask(question) ⇒ Object
- #error(reason) ⇒ Object
- #get_author(authors) ⇒ Object
- #get_date(label) ⇒ Object
- #get_project_id(projects) ⇒ Object
- #get_user_id(users) ⇒ Object
- #print_welcome ⇒ Object
Instance Method Details
#ask(question) ⇒ Object
17 18 19 20 |
# File 'lib/git2mite/gui.rb', line 17 def ask(question) print "#{question}: " $stdin.gets end |
#error(reason) ⇒ Object
22 23 24 25 |
# File 'lib/git2mite/gui.rb', line 22 def error(reason) STDERR.puts reason exit(-1) end |
#get_author(authors) ⇒ Object
45 46 47 48 49 50 51 52 |
# File 'lib/git2mite/gui.rb', line 45 def () puts "\n=== Git Authors ===" .each.with_index do |name, i| puts "#{i+1}\t#{name}" end choice = ask('Which author\'s commits to you want to use?') [choice.to_i - 1] || error('Invalid author') end |
#get_date(label) ⇒ Object
54 55 56 57 58 59 60 61 |
# File 'lib/git2mite/gui.rb', line 54 def get_date(label) answer = ask("Enter the #{label} (yyyy-mm-dd) [#{Date.today}]") begin answer.strip.empty? ? Date.today : Date.parse(answer) rescue(ArgumentError) error('invalid date') end end |
#get_project_id(projects) ⇒ Object
27 28 29 30 31 32 33 34 |
# File 'lib/git2mite/gui.rb', line 27 def get_project_id(projects) puts "=== Projects ===" projects.each.with_index do |project, i| puts "#{i+1}\t#{project['project']['name']}" end choice = ask('Which project do you want to write your commits to?') (projects[choice.to_i - 1] || error('invalid project id'))['project']['id'] end |
#get_user_id(users) ⇒ Object
36 37 38 39 40 41 42 43 |
# File 'lib/git2mite/gui.rb', line 36 def get_user_id(users) puts "\n=== Users ===" users.each.with_index do |user, i| puts "#{i+1}\t#{user.name}" end choice = ask('Which user do you want to write your commits to?') (users[choice.to_i - 1] || error('invalid user id')).id end |
#print_welcome ⇒ Object
3 4 5 6 7 8 9 10 11 12 13 14 15 |
# File 'lib/git2mite/gui.rb', line 3 def print_welcome puts <<-WELCOME Welcome to git2mite This tool allows to you to write the commit log of your git repository to your mite account in order to auto-fill your timesheets. Brought to you by http://upstre.am Questions, Problems, Source Code: http://github.com/upstream/git2mite WELCOME end |