Class: 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
Methods inherited from Base
Constructor Details
#initialize(config) ⇒ Slides
Returns a new instance of Slides.
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/diamante/scenes/slides.rb', line 12 def initialize(config) @config = config @pastel = Pastel.new @term = ANSI.new @height = @term.height @width = @term.width @files = Dir.glob(@config[:files]) if @files.empty? ANSI.set_cooked_mode warn "[ERROR] No slides! Revise config.yaml" exit 1 end @index = 0 end |
Instance Attribute Details
#index ⇒ Object (readonly)
Returns the value of attribute index.
10 11 12 |
# File 'lib/diamante/scenes/slides.rb', line 10 def index @index end |
Instance Method Details
#count ⇒ Object
29 30 31 |
# File 'lib/diamante/scenes/slides.rb', line 29 def count @files.count end |
#next ⇒ Object
45 46 47 48 49 |
# File 'lib/diamante/scenes/slides.rb', line 45 def next return unless @index + 1 < @files.size @index += 1 end |
#prev ⇒ Object
51 52 53 54 55 |
# File 'lib/diamante/scenes/slides.rb', line 51 def prev return unless @index > 0 @index -= 1 end |
#render ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/diamante/scenes/slides.rb', line 33 def render lines = @slide row = (@height / 2) - (lines.size / 2) max_with = lines.map(&:length).max || 0 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 |