Class: Path

Inherits:
Element show all
Defined in:
lib/parsers/path.rb

Instance Method Summary collapse

Constructor Details

#initializePath

Returns a new instance of Path.



4
5
6
7
# File 'lib/parsers/path.rb', line 4

def initialize
  super
  @pathdefs = []
end

Instance Method Details

#<<(token) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/parsers/path.rb', line 9

def <<(token)
  if @tokens.empty?
    raise "Invalid starting token: #{token}" unless token.first == :PATH
  end

  if token.first == :LOCATION
    x, y = token.last
    @points << [x, y]
  elsif token.first == :ATTRIBUTE
    k, v = token.last
    @attributes[k] = v
  elsif token.first == :PATHDEF
    command, params = token.last
    @pathdefs << [command, params]
  end

  super(token)
end

#translateObject



28
29
30
31
32
# File 'lib/parsers/path.rb', line 28

def translate
  attrs = @attributes.map { |k,v| "#{k}='#{v}'" }.join(' ')
  definition = @pathdefs.map { |command, params| "#{command} #{params}" }.join(' ')
  "<path d='#{definition}' #{attrs} />"
end