Class: Diamante::Scene::Slides
- Inherits:
-
Object
- Object
- Diamante::Scene::Slides
- Defined in:
- lib/diamante/scenes/slides.rb
Instance Attribute Summary collapse
-
#index ⇒ Object
readonly
Returns the value of attribute index.
Instance Method Summary collapse
- #count ⇒ Object
-
#initialize(config) ⇒ Slides
constructor
A new instance of Slides.
- #next ⇒ Object
- #prev ⇒ Object
- #render ⇒ Object
Constructor Details
#initialize(config) ⇒ Slides
Returns a new instance of Slides.
11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/diamante/scenes/slides.rb', line 11 def initialize(config) @config = config @pastel = Pastel.new @term = ANSI.new @height = @term.height @width = @term.width @files = Dir.glob(@config[:files]) @index = 0 end |
Instance Attribute Details
#index ⇒ Object (readonly)
Returns the value of attribute index.
9 10 11 |
# File 'lib/diamante/scenes/slides.rb', line 9 def index @index end |
Instance Method Details
#count ⇒ Object
23 24 25 |
# File 'lib/diamante/scenes/slides.rb', line 23 def count @files.count end |
#next ⇒ Object
39 40 41 42 43 |
# File 'lib/diamante/scenes/slides.rb', line 39 def next return unless @index + 1 < @files.size @index += 1 end |
#prev ⇒ Object
45 46 47 48 49 |
# File 'lib/diamante/scenes/slides.rb', line 45 def prev return unless @index > 0 @index -= 1 end |
#render ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/diamante/scenes/slides.rb', line 27 def render lines = @slide row = (@height / 2) - (lines.size / 2) max_with = lines.map(&:length).max col = (@width / 2) - (max_with / 2) lines.each_with_index do |text, index| text = @pastel.white.bold(text) ANSI.print_text_at(row + 1 + index, col,text) end end |