Class: Rect

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

Instance Method Summary collapse

Methods inherited from Element

#initialize

Constructor Details

This class inherits a constructor from Element

Instance Method Details

#<<(token) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/parsers/rect.rb', line 4

def <<(token)
  if @tokens.empty?
    raise "Invalid starting token: #{token}" unless token.first == :RECT
    w, h = token.last
    @attributes['width'] = w
    @attributes['height'] = h
  end

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

  super(token)
end

#translateObject



24
25
26
27
# File 'lib/parsers/rect.rb', line 24

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