Class: Lolcommits::CLI::TimelapseGif

Inherits:
Object
  • Object
show all
Defined in:
lib/lolcommits/cli/timelapse_gif.rb

Overview

Creates an animated timeline GIF of lolcommits history.

Instance Method Summary collapse

Constructor Details

#initialize(config) ⇒ TimelapseGif

param config [Lolcommits::Configuration]



11
12
13
# File 'lib/lolcommits/cli/timelapse_gif.rb', line 11

def initialize(config)
  @configuration = config
end

Instance Method Details

#run(args = nil) ⇒ Object

Runs the history timeline animator task thingy param args [String] the arg passed to the gif command on CLI (optional)



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/lolcommits/cli/timelapse_gif.rb', line 17

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.to_s].flatten)

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