Class: DynamicSprites::Generator

Inherits:
Object
  • Object
show all
Defined in:
lib/dynamic-sprites/generator.rb

Overview

Generates sprites

Constant Summary collapse

VALID_EXTENSIONS =

Array of file extensions used for creating sprites.

%w(.png .jpg .jpeg .gif .ico)

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(filename, path, layout) ⇒ Generator

Initializer

filename - Pathname where generated file should be placed to. path - Pathname of directory containing source images. layout - sprite layout name as a String



19
20
21
22
23
# File 'lib/dynamic-sprites/generator.rb', line 19

def initialize(filename, path, layout)
  @filename = filename
  @layout = layout
  @files = Dir.glob(File.join(path, '*')).select { |e| VALID_EXTENSIONS.include?(File.extname(e)) }
end

Instance Attribute Details

#filenameObject (readonly)

Returns the value of attribute filename.



9
10
11
# File 'lib/dynamic-sprites/generator.rb', line 9

def filename
  @filename
end

#filesObject (readonly)

Returns the value of attribute files.



11
12
13
# File 'lib/dynamic-sprites/generator.rb', line 11

def files
  @files
end

#layoutObject (readonly)

Returns the value of attribute layout.



10
11
12
# File 'lib/dynamic-sprites/generator.rb', line 10

def layout
  @layout
end

Instance Method Details

#run!Object

Main method for sprites generation



27
28
29
# File 'lib/dynamic-sprites/generator.rb', line 27

def run!
  create(filename, load(files), layout)
end