Class: Text

Inherits:
Element show all
Defined in:
lib/parsers/text.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
# File 'lib/parsers/text.rb', line 4

def <<(token)
  if @tokens.empty?
    raise "Invalid starting token: #{token}" unless token.first == :TEXT
    @text = token.last
  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



22
23
24
25
# File 'lib/parsers/text.rb', line 22

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