Sha256: 94ad0c2b7e5c776dc253395e11a3afa48a64eb503c01efe344b22043f747eafc

Contents?: true

Size: 1.3 KB

Versions: 1

Compression:

Stored size: 1.3 KB

Contents

module TP
  class SlideDeck
    attr_accessor :cursor, :slides

    def initialize(slides)
      self.cursor = 0
      self.slides = slides
    end

    def [](index)
      frames[index]
    end

    def current
      frames[cursor]
    end
    alias current_frame current

    def ended?
      not current
    end

    def frames
      return @frames if @frames

      @frames = []

      slides.each do |slide|
        if slide.bullets
          buffer = "# #{slide.header}"

          @frames << Slide.new(buffer)

          buffer << "\n"

          slide.bullets.each do |bullet|
            buffer << "\n* #{bullet}"
            @frames << Slide.new(buffer)
          end
        else
          @frames << Slide.new("# #{slide.header}\n\n#{slide.body}")
        end
      end

      @frames
    end

    def next
      self.cursor += 1

      current
    end

    def previous
      self.cursor -= 1

      current
    end

    def width
      slides_without_paragraphs = slides.reject(&:paragraph)

      if slides_without_paragraphs.empty?
        [slides.collect(&:width).max, 80].min
      else
        [
          slides.collect(&:header).map(&:length).max,
          slides_without_paragraphs.collect(&:width).max
        ].max
      end
    end

    def height
      slides.collect(&:height).max
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
tp-0.3.1 lib/tp/slide_deck.rb