Class: Parser
- Inherits:
-
Object
- Object
- Parser
- Defined in:
- lib/parser.rb
Instance Attribute Summary collapse
-
#els ⇒ Object
readonly
Returns the value of attribute els.
Instance Method Summary collapse
-
#initialize(tokens) ⇒ Parser
constructor
A new instance of Parser.
- #translate ⇒ Object
Constructor Details
#initialize(tokens) ⇒ Parser
Returns a new instance of Parser.
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/parser.rb', line 14 def initialize(tokens) @els = Svg.new curr = @els # TODO: Switch to a state machine framework (state_machine, Ragel); # this is getting gross. tokens.each do |token| if curr == @els if token.first == :DIMENSION el = Svg.new el << token @els = el curr = el elsif token.first == :SASS el = SassEl.new el << token curr << el curr = el elsif token.first == :CIRCLE el = Circle.new el << token curr << el curr = el elsif token.first == :ELLIPSE el = Ellipse.new el << token curr << el curr = el elsif token.first == :ROUND_RECT el = RoundRect.new el << token curr << el curr = el elsif token.first == :RECT el = Rect.new el << token curr << el curr = el elsif token.first == :TEXT el = Text.new el << token curr << el curr = el elsif token.first == :LINE el = Line.new el << token curr << el curr = el elsif token.first == :PATH el = Path.new el << token curr << el curr = el end else if [:EOF, :DEDENT, :NEWLINE].include? token.first curr = @els else curr << token end end end end |
Instance Attribute Details
#els ⇒ Object (readonly)
Returns the value of attribute els.
12 13 14 |
# File 'lib/parser.rb', line 12 def els @els end |
Instance Method Details
#translate ⇒ Object
78 79 80 |
# File 'lib/parser.rb', line 78 def translate @els.translate end |