Class: Link
Overview
Handles logic for Link tokens
Constant Summary
Constants inherited
from BasicToken
BasicToken::INLINE_CLASS_NAMES, BasicToken::TOP_LEVEL_CLASS_NAMES
Instance Attribute Summary
Attributes inherited from BasicToken
#source_text
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from BasicToken
#accept, #initialize, #inline?
Constructor Details
This class inherits a constructor from BasicToken
Class Method Details
.consume(text) ⇒ Object
19
20
21
22
23
24
|
# File 'lib/rosetta/tokens/link.rb', line 19
def self.consume(text)
closing_index = text.rindex(')')
source = text[0..closing_index]
new(source)
end
|
.matches?(text) ⇒ Boolean
7
8
9
10
11
12
13
14
15
16
17
|
# File 'lib/rosetta/tokens/link.rb', line 7
def self.matches?(text)
return false unless text.start_with?('[')
closing_bracket_index = text.index(']')
return false if closing_bracket_index.nil?
return false if text[closing_bracket_index + 1] != '('
text[closing_bracket_index + 1..].include?(')')
end
|
Instance Method Details
#node_representation ⇒ Object
30
31
32
|
# File 'lib/rosetta/tokens/link.rb', line 30
def node_representation
"<#{type} value='#{value}' url='#{url}'>"
end
|
#to_s ⇒ Object
26
27
28
|
# File 'lib/rosetta/tokens/link.rb', line 26
def to_s
"<Token type='#{type}' value='#{value}' url='#{url}'>"
end
|
#type ⇒ Object
34
35
36
|
# File 'lib/rosetta/tokens/link.rb', line 34
def type
:LINK
end
|
#url ⇒ Object
45
46
47
48
|
# File 'lib/rosetta/tokens/link.rb', line 45
def url
@source_text[url_beginning_index + 1...-1]
end
|
#value ⇒ Object
38
39
40
41
42
43
|
# File 'lib/rosetta/tokens/link.rb', line 38
def value
final_bracket_index = url_beginning_index - 1
@source_text[1...final_bracket_index]
end
|