Class: Line

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

Instance Method Summary collapse

Constructor Details

#initializeLine

Returns a new instance of Line.



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

def initialize
  super
  @points = []
end

Instance Method Details

#<<(token) ⇒ Object



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

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

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

  super(token)
end

#translateObject



25
26
27
28
29
# File 'lib/parsers/line.rb', line 25

def translate
  attrs = @attributes.map { |k,v| "#{k}='#{v}'" }.join(' ')
  points = @points.map { |coords| coords.join(',') }.join(' ')
  "<polyline points='#{points}' #{attrs} />"
end