Class: Slideck::Tracker Private
- Inherits:
-
Object
- Object
- Slideck::Tracker
- Defined in:
- lib/slideck/tracker.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Responsible for tracking current slide number
Instance Attribute Summary collapse
-
#current ⇒ Integer
readonly
The current slide number.
-
#total ⇒ Integer
readonly
The total number of slides.
Class Method Summary collapse
-
.for(total) ⇒ Slideck::Tracker
Create a Tracker instance with the current slide set to zero.
Instance Method Summary collapse
-
#first ⇒ Slideck::Tracker
Move to the first slide.
-
#go_to(slide_no) ⇒ Slideck::Tracker
Go to a specific slide number.
-
#initialize(current, total) ⇒ Tracker
constructor
Create a Tracker instance.
-
#last ⇒ Slideck::Tracker
Move to the last slide.
-
#next ⇒ Slideck::Tracker
Move to the next slide.
-
#previous ⇒ Slideck::Tracker
Move to the previous slide.
-
#resize(new_total) ⇒ Slideck::Tracker
Resize to the new total.
Constructor Details
#initialize(current, total) ⇒ Tracker
Create a Tracker instance
54 55 56 57 58 59 |
# File 'lib/slideck/tracker.rb', line 54 def initialize(current, total) @current = current @total = total freeze end |
Instance Attribute Details
#current ⇒ Integer (readonly)
The current slide number
31 32 33 |
# File 'lib/slideck/tracker.rb', line 31 def current @current end |
#total ⇒ Integer (readonly)
The total number of slides
41 42 43 |
# File 'lib/slideck/tracker.rb', line 41 def total @total end |
Class Method Details
.for(total) ⇒ Slideck::Tracker
Create a Tracker instance with the current slide set to zero
19 20 21 |
# File 'lib/slideck/tracker.rb', line 19 def self.for(total) new(0, total) end |
Instance Method Details
#first ⇒ Slideck::Tracker
Move to the first slide
97 98 99 |
# File 'lib/slideck/tracker.rb', line 97 def first self.class.new(0, total) end |
#go_to(slide_no) ⇒ Slideck::Tracker
Go to a specific slide number
124 125 126 127 128 |
# File 'lib/slideck/tracker.rb', line 124 def go_to() return self if < 0 || total - 1 < self.class.new(, total) end |
#last ⇒ Slideck::Tracker
Move to the last slide
109 110 111 |
# File 'lib/slideck/tracker.rb', line 109 def last self.class.new(total - 1, total) end |
#next ⇒ Slideck::Tracker
Move to the next slide
69 70 71 72 73 |
# File 'lib/slideck/tracker.rb', line 69 def next return self if current >= total - 1 self.class.new(current + 1, total) end |
#previous ⇒ Slideck::Tracker
Move to the previous slide
83 84 85 86 87 |
# File 'lib/slideck/tracker.rb', line 83 def previous return self if current.zero? self.class.new(current - 1, total) end |
#resize(new_total) ⇒ Slideck::Tracker
Resize to the new total
141 142 143 144 145 |
# File 'lib/slideck/tracker.rb', line 141 def resize(new_total) return self if new_total < 0 || total == new_total self.class.new(reset_current(new_total), new_total) end |