Class: Path
Instance Method Summary collapse
- #<<(token) ⇒ Object
-
#initialize ⇒ Path
constructor
A new instance of Path.
- #translate ⇒ Object
Constructor Details
#initialize ⇒ Path
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 |
#translate ⇒ Object
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 |