Sha256: c5ec1108098a0445431283ffec32a440b6f09f1f5bfa7e655162d7ea3ccb9d5c

Contents?: true

Size: 1.2 KB

Versions: 4

Compression:

Stored size: 1.2 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)
        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.to_s].flatten)

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

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
lolcommits-0.9.2 lib/lolcommits/cli/timelapse_gif.rb
lolcommits-0.9.2.pre1 lib/lolcommits/cli/timelapse_gif.rb
lolcommits-0.9.1 lib/lolcommits/cli/timelapse_gif.rb
lolcommits-0.9.1.pre1 lib/lolcommits/cli/timelapse_gif.rb