Sha256: d08296eb56248a83af62cb284fcc0d6711ec8f320a03c83c31e0d87a7d08bce2

Contents?: true

Size: 830 Bytes

Versions: 1

Compression:

Stored size: 830 Bytes

Contents

require 'gifanime'

module Capybara
  module Animate
    class GifRecorder
      attr_reader :output_file

      def initialize(output_name)
        @output_file = "#{output_name}.gif"
        make_path_unless_exists(output_file)
        @gif_anime = Gifanime.new(output_file, delay: 40)
        @tmpdir = Dir.mktmpdir
      end

      def add(page)
        file = "#{tmpdir}/#{current_frame}.png"
        page.save_screenshot(file, width: 320, height: 480)
        gif_anime.add(file)
      end

      def generate!
        gif_anime.generate!
      end

      private
      attr_reader :tmpdir, :gif_anime

      def current_frame
        gif_anime.frames.length
      end

      def make_path_unless_exists(file)
        FileUtils.mkdir_p(File.dirname(file)) unless File.exists?(File.dirname(file))
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
capybara-animate-0.1.0 lib/capybara/animate/gif_recorder.rb