Class: GitPresenter::Presentation
- Inherits:
-
Object
- Object
- GitPresenter::Presentation
- Defined in:
- lib/git_presenter/presentation.rb
Instance Attribute Summary collapse
-
#current_slide ⇒ Object
readonly
Returns the value of attribute current_slide.
-
#slides ⇒ Object
readonly
Returns the value of attribute slides.
Instance Method Summary collapse
- #bash_command(user_command) ⇒ Object
- #command_for(command) ⇒ Object
- #commit(slide_number) ⇒ Object
- #end ⇒ Object
- #execute(user_command) ⇒ Object
- #exit ⇒ Object
- #find_current_slide ⇒ Object
- #help ⇒ Object
-
#initialize(presentation, shell = GitPresenter::Shell.new) ⇒ Presentation
constructor
A new instance of Presentation.
- #list ⇒ Object
- #next ⇒ Object
- #position ⇒ Object
- #previous ⇒ Object
- #start ⇒ Object
- #status_line ⇒ Object
- #total_slides ⇒ Object
Constructor Details
#initialize(presentation, shell = GitPresenter::Shell.new) ⇒ Presentation
Returns a new instance of Presentation.
4 5 6 7 8 9 |
# File 'lib/git_presenter/presentation.rb', line 4 def initialize(presentation, shell=GitPresenter::Shell.new) @branch = presentation["branch"] @slides = presentation["slides"].map{|| GitPresenter::Slide.new(["slide"])} @shell = shell @current_slide = end |
Instance Attribute Details
#current_slide ⇒ Object (readonly)
Returns the value of attribute current_slide.
2 3 4 |
# File 'lib/git_presenter/presentation.rb', line 2 def @current_slide end |
#slides ⇒ Object (readonly)
Returns the value of attribute slides.
2 3 4 |
# File 'lib/git_presenter/presentation.rb', line 2 def @slides end |
Instance Method Details
#bash_command(user_command) ⇒ Object
40 41 42 |
# File 'lib/git_presenter/presentation.rb', line 40 def bash_command(user_command) puts `#{user_command[1..-1]}` end |
#command_for(command) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/git_presenter/presentation.rb', line 16 def command_for(command) return :commit if command =~ /^[0-9]+$/ return :command if command[0] == "!" {"n" => :next, "next" => :next, "back" => :previous, "b" => :previous, "start" => :start, "s" => :start, "end" => :end, "e" => :end, "list" => :list, "l" => :list, "help" => :help, "h" => :help, "exit" => :exit }[command] end |
#commit(slide_number) ⇒ Object
86 87 88 89 |
# File 'lib/git_presenter/presentation.rb', line 86 def commit() @current_slide = [ - 1] @current_slide.execute end |
#end ⇒ Object
81 82 83 84 |
# File 'lib/git_presenter/presentation.rb', line 81 def end @current_slide = .last @current_slide.execute end |
#execute(user_command) ⇒ Object
29 30 31 32 33 34 35 36 37 38 |
# File 'lib/git_presenter/presentation.rb', line 29 def execute(user_command) command = command_for(user_command) if command.nil? puts "I canny understand ye, gonna try again" return end return commit(user_command.to_i) if command == :commit return bash_command(user_command) if command == :command self.send(command) end |
#exit ⇒ Object
48 49 50 51 |
# File 'lib/git_presenter/presentation.rb', line 48 def exit `git checkout -q #{@branch}` :exit end |
#find_current_slide ⇒ Object
11 12 13 14 |
# File 'lib/git_presenter/presentation.rb', line 11 def sha = @shell.run("git rev-parse HEAD").strip @slides.detect{|s| s.commit == sha} end |
#help ⇒ Object
66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/git_presenter/presentation.rb', line 66 def help <<-EOH Git Presenter Reference next/n: move to next slide back/b: move back a slide end/e: move to end of presentation start/s: move to start of presentation list/l : list slides in presentation help/h: display this message !(exclimation mark): execute following in terminal exit: exit from the presentation EOH end |
#list ⇒ Object
103 104 105 106 107 108 109 110 111 |
# File 'lib/git_presenter/presentation.rb', line 103 def list @slides.map do || if == @current_slide "*#{}" else end end.join("\n") end |
#next ⇒ Object
91 92 93 94 95 |
# File 'lib/git_presenter/presentation.rb', line 91 def next return if position.nil? @current_slide = [position + 1] || @current_slide @current_slide.execute end |
#position ⇒ Object
53 54 55 |
# File 'lib/git_presenter/presentation.rb', line 53 def position @slides.index(@current_slide) end |
#previous ⇒ Object
97 98 99 100 101 |
# File 'lib/git_presenter/presentation.rb', line 97 def previous return @current_slide if position == 0 @current_slide = [position - 1] @current_slide.execute end |
#start ⇒ Object
61 62 63 64 |
# File 'lib/git_presenter/presentation.rb', line 61 def start @current_slide = .first @current_slide.execute end |
#status_line ⇒ Object
44 45 46 |
# File 'lib/git_presenter/presentation.rb', line 44 def status_line "#{position+1}/#{} >" end |
#total_slides ⇒ Object
57 58 59 |
# File 'lib/git_presenter/presentation.rb', line 57 def @slides.length end |