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
- #help ⇒ Object
-
#initialize(presentation) ⇒ 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) ⇒ Presentation
Returns a new instance of Presentation.
4 5 6 7 |
# File 'lib/git_presenter/presentation.rb', line 4 def initialize(presentation) = presentation["slides"].map{|| GitPresenter::Slide.new(["slide"])} = .first 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 end |
#slides ⇒ Object (readonly)
Returns the value of attribute slides.
2 3 4 |
# File 'lib/git_presenter/presentation.rb', line 2 def end |
Instance Method Details
#bash_command(user_command) ⇒ Object
33 34 35 |
# File 'lib/git_presenter/presentation.rb', line 33 def bash_command(user_command) puts `#{user_command[1..-1]}` end |
#command_for(command) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/git_presenter/presentation.rb', line 9 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
79 80 81 82 |
# File 'lib/git_presenter/presentation.rb', line 79 def commit() = [ - 1] .execute end |
#end ⇒ Object
74 75 76 77 |
# File 'lib/git_presenter/presentation.rb', line 74 def end = .last .execute end |
#execute(user_command) ⇒ Object
22 23 24 25 26 27 28 29 30 31 |
# File 'lib/git_presenter/presentation.rb', line 22 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
41 42 43 44 |
# File 'lib/git_presenter/presentation.rb', line 41 def exit `git checkout -q master` :exit end |
#help ⇒ Object
59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/git_presenter/presentation.rb', line 59 def help "Git Presenter Reference\n\nnext/n: move to next slide\nback/b: move back a slide\nend/e: move to end of presentation\nstart/s: move to start of presentation\nlist/l : list slides in presentation\nhelp/h: display this message\n!(exclimation mark): execute following in terminal\nexit: exit from the presentation\n" end |
#list ⇒ Object
96 97 98 99 100 101 102 103 104 |
# File 'lib/git_presenter/presentation.rb', line 96 def list .map do || if == "*#{slide}" else end end.join("\n") end |
#next ⇒ Object
84 85 86 87 88 |
# File 'lib/git_presenter/presentation.rb', line 84 def next return if position.nil? = [position + 1] || .execute end |
#position ⇒ Object
46 47 48 |
# File 'lib/git_presenter/presentation.rb', line 46 def position .index() end |
#previous ⇒ Object
90 91 92 93 94 |
# File 'lib/git_presenter/presentation.rb', line 90 def previous return if position == 0 = [position - 1] .execute end |
#start ⇒ Object
54 55 56 57 |
# File 'lib/git_presenter/presentation.rb', line 54 def start = .first .execute end |
#status_line ⇒ Object
37 38 39 |
# File 'lib/git_presenter/presentation.rb', line 37 def status_line "#{position+1}/#{total_slides} >" end |
#total_slides ⇒ Object
50 51 52 |
# File 'lib/git_presenter/presentation.rb', line 50 def .length end |