Class: BasicToken

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

Overview

Holds logic and information for basic token management.

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

Instance Method Summary collapse

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_textObject (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

Returns:

  • (Boolean)


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_representationObject



23
24
25
# File 'lib/rosetta/tokens/basic_token.rb', line 23

def node_representation
  "<#{type} value='#{value}'>"
end

#to_sObject



19
20
21
# File 'lib/rosetta/tokens/basic_token.rb', line 19

def to_s
  "<Token type='#{type}' value='#{value}'>"
end

#typeObject



27
28
29
# File 'lib/rosetta/tokens/basic_token.rb', line 27

def type
  raise 'Subclass should handle type.'
end

#valueObject



31
32
33
# File 'lib/rosetta/tokens/basic_token.rb', line 31

def value
  raise 'Subclass should handle value.'
end