Class: BlockToken

Inherits:
Object
  • Object
show all
Defined in:
lib/rosetta/tokens/block_token.rb

Overview

Holds logic and information for block token management.

Direct Known Subclasses

BasicList, BlockQuote, CodeBlock, NumberedList, Paragraph

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(tokens) ⇒ BlockToken

Returns a new instance of BlockToken.



7
8
9
# File 'lib/rosetta/tokens/block_token.rb', line 7

def initialize(tokens)
  @children = tokens
end

Instance Attribute Details

#childrenObject (readonly)

Returns the value of attribute children.



5
6
7
# File 'lib/rosetta/tokens/block_token.rb', line 5

def children
  @children
end

Instance Method Details

#accept(visitor) ⇒ Object



32
33
34
35
# File 'lib/rosetta/tokens/block_token.rb', line 32

def accept(visitor)
  method_name = "generate_#{type.to_s.downcase}"
  visitor.send(method_name.to_sym, self)
end

#node_representationObject



15
16
17
18
19
20
21
22
# File 'lib/rosetta/tokens/block_token.rb', line 15

def node_representation
  opening_tag = "<#{type} child_count=#{children.count}>"
  closing_tag = "<#{type} />"

  contents = children.map { |token| "  #{token.node_representation}" }.join("\n")

  "#{opening_tag}\n#{contents}\n#{closing_tag}"
end

#to_sObject



11
12
13
# File 'lib/rosetta/tokens/block_token.rb', line 11

def to_s
  "<Token type='#{type}' child_count='#{children.count}' children='#{children}'>"
end

#typeObject



24
25
26
# File 'lib/rosetta/tokens/block_token.rb', line 24

def type
  raise 'Subclass should handle #type.'
end

#valueObject



28
29
30
# File 'lib/rosetta/tokens/block_token.rb', line 28

def value
  raise 'Subclass should handle #value.'
end