Class: Blacksmith::FontBuilder
- Inherits:
-
Object
- Object
- Blacksmith::FontBuilder
show all
- Defined in:
- lib/blacksmith/font_builder.rb
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(filename = nil, &block) ⇒ FontBuilder
Returns a new instance of FontBuilder.
10
11
12
13
14
15
16
17
18
19
20
|
# File 'lib/blacksmith/font_builder.rb', line 10
def initialize(filename = nil, &block)
raise "Expects filename or block" unless filename || block
raise "Expects either a block or a filename - not both" if filename and block
raise "File not found: #{filename}" unless filename && File.exist?(filename)
@_instructions = block || File.read(filename)
@_attributes = {}
@_glyphs = {}
@_source = '.'
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args) ⇒ Object
47
48
49
50
51
52
53
|
# File 'lib/blacksmith/font_builder.rb', line 47
def method_missing(name, *args)
if args.length == 1
@_attributes[name] = args[0]
else
super
end
end
|
Class Method Details
.execute(*args, &block) ⇒ Object
4
5
6
|
# File 'lib/blacksmith/font_builder.rb', line 4
def execute(*args, &block)
new(*args, &block).execute
end
|
Instance Method Details
#execute ⇒ Object
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
|
# File 'lib/blacksmith/font_builder.rb', line 22
def execute
case @_instructions
when String
instance_eval(@_instructions)
when Proc
instance_eval(&@_instructions)
end
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
43
44
45
|
# File 'lib/blacksmith/font_builder.rb', line 43
def glyph(name, attrs)
@_glyphs[name] = attrs
end
|