Class: FaviconMaker::Creator

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

Constant Summary collapse

RECENT_IM_VERSION =
"6.8.0"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(template_file_path, output_path, options, finished_block) ⇒ Creator

Returns a new instance of Creator.



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/favicon_maker/creator.rb', line 13

def initialize(template_file_path, output_path, options, finished_block)
  @template_file_path = template_file_path
  @output_path        = output_path
  @options            = options
  @finished_block     = finished_block
  @command_set        = []

  im_version = fetch_image_magick_version

  if im_version
    print_image_magick_ancient_version_warning(im_version) if im_version < RECENT_IM_VERSION
  else
    print_image_magick_no_version_warning
  end
end

Instance Attribute Details

#finished_blockObject

Returns the value of attribute finished_block.



11
12
13
# File 'lib/favicon_maker/creator.rb', line 11

def finished_block
  @finished_block
end

#optionsObject

Returns the value of attribute options.



10
11
12
# File 'lib/favicon_maker/creator.rb', line 10

def options
  @options
end

#output_pathObject

Returns the value of attribute output_path.



9
10
11
# File 'lib/favicon_maker/creator.rb', line 9

def output_path
  @output_path
end

#template_file_pathObject

Returns the value of attribute template_file_path.



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

def template_file_path
  @template_file_path
end

Instance Method Details

#icon(output_filename, options = {}) ⇒ Object



29
30
31
32
33
34
35
36
37
# File 'lib/favicon_maker/creator.rb', line 29

def icon(output_filename, options={})
  format  = options[:format]  || extract_format(output_filename)
  size    = options[:size]    || extract_size(output_filename)
  output_file_path = File.join(output_path, output_filename)

  validate_input(format, size)

  @command_set << [ generate_command(template_file_path, output_file_path, size, format), output_file_path, template_file_path ]
end

#runObject



39
40
41
42
43
44
# File 'lib/favicon_maker/creator.rb', line 39

def run
  @command_set.map do |cmd, output_file_path, template_file_path|
    `#{cmd}`
    finished_block.call(output_file_path, template_file_path) if finished_block
  end
end