Class: BasicToken
- Inherits:
-
Object
- Object
- BasicToken
- Defined in:
- lib/rosetta/tokens/basic_token.rb
Overview
Holds logic and information for basic token management.
Direct Known Subclasses
BasicListItem, Bold, Break, CodeBlockDelimiter, Header, InlineCode, Italics, LineBreak, Link, NewLine, NumberedListItem, Quote, Strikethrough, Text
Constant Summary collapse
- TOP_LEVEL_CLASS_NAMES =
[ :Header, :LineBreak, :Quote, :CodeBlockDelimiter, :BasicListItem, :NumberedListItem, :Link ].freeze
- INLINE_CLASS_NAMES =
[:Bold, :Italics, :Strikethrough, :InlineCode, :Link].freeze
Instance Attribute Summary collapse
-
#source_text ⇒ Object
readonly
Returns the value of attribute source_text.
Instance Method Summary collapse
- #accept(visitor) ⇒ Object
-
#initialize(source_text) ⇒ BasicToken
constructor
A new instance of BasicToken.
-
#inline? ⇒ Boolean
TODO: Make references to token type constant everywhere.
- #node_representation ⇒ Object
- #to_s ⇒ Object
- #type ⇒ Object
- #value ⇒ Object
Constructor Details
#initialize(source_text) ⇒ BasicToken
Returns a new instance of BasicToken.
15 16 17 |
# File 'lib/rosetta/tokens/basic_token.rb', line 15 def initialize(source_text) @source_text = source_text end |
Instance Attribute Details
#source_text ⇒ Object (readonly)
Returns the value of attribute source_text.
13 14 15 |
# File 'lib/rosetta/tokens/basic_token.rb', line 13 def source_text @source_text end |
Instance Method Details
#accept(visitor) ⇒ Object
35 36 37 38 |
# File 'lib/rosetta/tokens/basic_token.rb', line 35 def accept(visitor) method_name = "generate_#{type.to_s.downcase}" visitor.send(method_name.to_sym, self) end |
#inline? ⇒ Boolean
TODO: Make references to token type constant everywhere
41 42 43 |
# File 'lib/rosetta/tokens/basic_token.rb', line 41 def inline? INLINE_CLASS_NAMES.include?(camel_case_type) || type == :TEXT end |
#node_representation ⇒ Object
23 24 25 |
# File 'lib/rosetta/tokens/basic_token.rb', line 23 def node_representation "<#{type} value='#{value}'>" end |
#to_s ⇒ Object
19 20 21 |
# File 'lib/rosetta/tokens/basic_token.rb', line 19 def to_s "<Token type='#{type}' value='#{value}'>" end |
#type ⇒ Object
27 28 29 |
# File 'lib/rosetta/tokens/basic_token.rb', line 27 def type raise 'Subclass should handle type.' end |
#value ⇒ Object
31 32 33 |
# File 'lib/rosetta/tokens/basic_token.rb', line 31 def value raise 'Subclass should handle value.' end |