Class: Blacksmith::FontBuilder

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

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(&block) ⇒ FontBuilder

Returns a new instance of FontBuilder.



10
11
12
13
14
15
# File 'lib/blacksmith/font_builder.rb', line 10

def initialize(&block)
  @_instructions = block
  @_attributes = {}
  @_glyphs = {}
  @_source = '.'
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args) ⇒ Object



37
38
39
40
41
42
43
# File 'lib/blacksmith/font_builder.rb', line 37

def method_missing(name, *args)
  if args.length == 1
    @_attributes[name] = args[0]
  else
    super
  end
end

Class Method Details

.execute(&block) ⇒ Object



4
5
6
# File 'lib/blacksmith/font_builder.rb', line 4

def execute(&block)
  new(&block).execute
end

Instance Method Details

#executeObject



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/blacksmith/font_builder.rb', line 17

def execute
  instance_eval(&@_instructions)
  
  font = Blacksmith::Font.new(@_attributes)
  
  @_glyphs.each do |name, attrs|
    attrs[:scale]   ||= font.scale
    attrs[:offset]  ||= font.offset
    attrs[:outline] ||= File.join(font.source, "#{name}.svg")
    
    font << Blacksmith::Glyph.new(attrs)
  end
  
  font
end

#glyph(name, attrs) ⇒ Object



33
34
35
# File 'lib/blacksmith/font_builder.rb', line 33

def glyph(name, attrs)
  @_glyphs[name] = attrs
end