Class: VCSRuby::Tools

Inherits:
Object
  • Object
show all
Defined in:
lib/tools.rb

Defined Under Namespace

Classes: MagickVersion

Class Method Summary collapse

Class Method Details

.contact_sheet_with_options(video, options) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/tools.rb', line 32

def self.contact_sheet_with_options video, options
  Configuration.instance.load_profile options[:profile] if options[:profile]
  Configuration.instance.capturer = options[:capturer]

  video = VCSRuby::Video.new video
  
  unless video.valid?
    puts "Video '#{video.full_path}' cannot be read by Capturer '#{video.capturer_name}'"
    return nil
  end
  
  sheet = video.contact_sheet

  sheet.format = options[:format] if options[:format]
  sheet.title = options[:title] if options[:title]
  sheet.signature = options[:signature] if options[:signature]
  sheet.signature = nil if options[:no_signature]

  if options[:rows] || options[:columns] || options[:interval]
    sheet.initialize_geometry(options[:rows], options[:columns], options[:interval])
  end

  if options[:width] && options[:height]
    sheet.aspect_ratio = Rational(options[:width], options[:height])
  else
    sheet.aspect_ratio = options[:aspect_ratio] if options[:aspect_ratio]      
  end
  sheet.thumbnail_width = options[:width] if options[:width]
  sheet.thumbnail_height = options[:height] if options[:height]
  sheet.from = options[:from] if options[:from]
  sheet.to = options[:to] if options[:to]
  sheet.highlight = options[:highlight] if options[:highlight]

  sheet.timestamp = options[:timestamp] if options[:timestamp] != nil
  sheet.softshadow = options[:softshadow] if options[:softshadow] != nil
  sheet.polaroid = options[:polaroid] if options[:polaroid] != nil

  return sheet
end

.linux?Boolean

Returns:

  • (Boolean)


12
13
14
# File 'lib/tools.rb', line 12

def self.linux?
  return ((RUBY_PLATFORM =~ /linux/) or (RbConfig::CONFIG['host_os'] =~ /linux/i))
end

.list_arguments(arguments) ⇒ Object



16
17
18
# File 'lib/tools.rb', line 16

def self.list_arguments arguments
  arguments.map{ |argument| argument.to_s }.join(', ')
end

.magick_versionObject



26
27
28
29
30
# File 'lib/tools.rb', line 26

def self.magick_version
  output = %x[convert -version]
  m = output.match(/(\d+)\.(\d+)\.(\d+)(-(\d+))?/)
  MagickVersion.new(m[1].to_i, m[2].to_i, m[3].to_i)
end


20
21
22
23
# File 'lib/tools.rb', line 20

def self.print_help optparse
  puts optparse.summarize
  exit 0
end

.to_human_size(size) ⇒ Object



72
73
74
75
76
77
78
79
# File 'lib/tools.rb', line 72

def self.to_human_size size
  powers = { 'B'  => 1 << 10, 'KiB' => 1 << 20, 'MiB' => 1 << 30, 'GiB' => 1 << 40, 'TiB' => 1 << 50 }
  powers.each_pair do |prefix, power|
    if size < power
      return format('%.2f',size.to_f / (power >> 10)) + ' ' + prefix
    end
  end
end

.windows?Boolean

Returns:

  • (Boolean)


8
9
10
# File 'lib/tools.rb', line 8

def self.windows?
  return ((RUBY_PLATFORM =~ /win32/ or RUBY_PLATFORM =~ /mingw32/) or (RbConfig::CONFIG['host_os'] =~ /mswin|windows/i))
end