Class: Tzispa::Rig::TypeToken::Loop

Inherits:
Tzispa::Rig::Token show all
Extended by:
Forwardable
Defined in:
lib/tzispa/rig/type_token/statement.rb

Constant Summary

Constants inherited from Tzispa::Rig::Token

Tzispa::Rig::Token::RE_ANCHOR

Instance Attribute Summary collapse

Attributes inherited from Tzispa::Rig::Token

#parser, #type

Instance Method Summary collapse

Methods inherited from Tzispa::Rig::Token

#anchor, instance

Constructor Details

#initialize(parser, match) ⇒ Loop

Returns a new instance of Loop.



15
16
17
18
19
# File 'lib/tzispa/rig/type_token/statement.rb', line 15

def initialize(parser, match)
  super(parser, :loop)
  @id = match[3].to_sym
  @body = match[4]
end

Instance Attribute Details

#body_parserObject (readonly)

Returns the value of attribute body_parser.



12
13
14
# File 'lib/tzispa/rig/type_token/statement.rb', line 12

def body_parser
  @body_parser
end

#idObject (readonly)

Returns the value of attribute id.



12
13
14
# File 'lib/tzispa/rig/type_token/statement.rb', line 12

def id
  @id
end

Instance Method Details

#parse!Object



21
22
23
24
25
26
27
28
# File 'lib/tzispa/rig/type_token/statement.rb', line 21

def parse!
  @body_parser = Rig::ParserNext.new template: template,
                                     text: @body,
                                     parent: parser,
                                     bindable: true
  @body_parser.parse!
  self
end

#render(binder) ⇒ Object



30
31
32
33
34
35
36
37
# File 'lib/tzispa/rig/type_token/statement.rb', line 30

def render(binder)
  String.new.tap do |text|
    looper = binder.data.send(@id) if binder.data.respond_to?(@id)
    looper&.data&.each do |loop_item|
      text << body_parser.render(loop_item) if loop_item
    end
  end
end