Class: SVGProcessor

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

Instance Method Summary collapse

Constructor Details

#initialize(path, prefix, sprite_path) ⇒ SVGProcessor

Returns a new instance of SVGProcessor.



4
5
6
7
8
# File 'lib/svg_processor.rb', line 4

def initialize(path, prefix, sprite_path)
  @path = path
  @prefix = prefix
  @sprite_path = sprite_path
end

Instance Method Details

#rebuildObject



10
11
12
13
14
15
16
17
18
19
20
# File 'lib/svg_processor.rb', line 10

def rebuild
  @svgs = Dir["#{@path}/*.svg"].map { |file| get_svg(file) }
  puts "rebuilding: #{@svgs.length} svgs found"
  @symbols = @svgs.map { |svg| convert_to_symbol(svg) }

  @symbol_string = @symbols.join("\n")

  if @sprite_path != nil
    File.write(@sprite_path, "<svg xmlns=\"http://www.w3.org/2000/svg\">#{@symbol_string}</svg>")
  end
end

#to_sObject



22
23
24
# File 'lib/svg_processor.rb', line 22

def to_s
  @symbol_string
end