Sha256: f0bae6f1943a40e9fc5c5c88e1cc315841a738dec2e60da8e166d62760b8fa86

Contents?: true

Size: 1.24 KB

Versions: 6

Compression:

Stored size: 1.24 KB

Contents

# -*- encoding: utf-8 -*-
require 'lolcommits/cli/fatals'

require 'mini_magick'

module Lolcommits
  module CLI
    # Creates an animated timeline GIF of lolcommits history.
    class TimelapseGif
      # param config [Lolcommits::Configuration]
      def initialize(config)
        @configuration = config
      end

      # Runs the history timeline animator task thingy
      # param args [String] the arg passed to the gif command on CLI (optional)
      def run(args = nil)
        Fatals.die_if_not_git_repo!

        case args
        when 'today'
          lolimages = @configuration.jpg_images_today
          filename  = "#{Date.today}.gif"
        else
          lolimages = @configuration.jpg_images
          filename  = 'archive.gif'
        end

        if lolimages.empty?
          warn 'No lolcommits have been captured for this time yet.'
          exit 1
        end

        puts '*** Generating animated gif.'

        gif = MiniMagick::Image.new File.join @configuration.archivedir, filename

        # This is for ruby 1.8.7, *lolimages just doesn't work with ruby 187
        gif.run_command('convert', *['-delay', '50', '-loop', '0', lolimages, "#{gif.path}"].flatten)

        puts "*** #{gif.path} generated."
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
lolcommits-0.6.1 lib/lolcommits/cli/timelapse_gif.rb
lolcommits-0.6.0 lib/lolcommits/cli/timelapse_gif.rb
lolcommits-0.5.9 lib/lolcommits/cli/timelapse_gif.rb
lolcommits-0.5.9.pre1 lib/lolcommits/cli/timelapse_gif.rb
lolcommits-0.5.8 lib/lolcommits/cli/timelapse_gif.rb
lolcommits-0.5.8.pre1 lib/lolcommits/cli/timelapse_gif.rb