Class: Rouge::Token
- Inherits:
-
Object
- Object
- Rouge::Token
- Defined in:
- lib/rouge/token.rb
Defined Under Namespace
Modules: Tokens
Class Attribute Summary collapse
-
.name ⇒ Object
readonly
Returns the value of attribute name.
-
.parent ⇒ Object
readonly
Returns the value of attribute parent.
-
.shortname ⇒ Object
readonly
Returns the value of attribute shortname.
Class Method Summary collapse
- .[](qualname) ⇒ Object
- .cache ⇒ Object
- .each_token(&b) ⇒ Object
- .inspect ⇒ Object
- .make_token(name, shortname, &b) ⇒ Object
- .matches?(other) ⇒ Boolean
- .qualname ⇒ Object
- .register! ⇒ Object
- .sub_tokens ⇒ Object
- .token(name, shortname, &b) ⇒ Object
- .token_chain ⇒ Object
Class Attribute Details
.name ⇒ Object (readonly)
Returns the value of attribute name.
7 8 9 |
# File 'lib/rouge/token.rb', line 7 def name @name end |
.parent ⇒ Object (readonly)
Returns the value of attribute parent.
8 9 10 |
# File 'lib/rouge/token.rb', line 8 def parent @parent end |
.shortname ⇒ Object (readonly)
Returns the value of attribute shortname.
9 10 11 |
# File 'lib/rouge/token.rb', line 9 def shortname @shortname end |
Class Method Details
.[](qualname) ⇒ Object
19 20 21 22 23 |
# File 'lib/rouge/token.rb', line 19 def [](qualname) return qualname unless qualname.is_a? ::String Token.cache[qualname] end |
.cache ⇒ Object
11 12 13 |
# File 'lib/rouge/token.rb', line 11 def cache @cache ||= {} end |
.each_token(&b) ⇒ Object
62 63 64 65 66 |
# File 'lib/rouge/token.rb', line 62 def each_token(&b) Token.cache.each do |(_, t)| b.call(t) end end |
.inspect ⇒ Object
25 26 27 |
# File 'lib/rouge/token.rb', line 25 def inspect "<Token #{qualname}>" end |
.make_token(name, shortname, &b) ⇒ Object
46 47 48 49 50 51 52 53 54 55 |
# File 'lib/rouge/token.rb', line 46 def make_token(name, shortname, &b) parent = self Class.new(parent) do @parent = parent @name = name @shortname = shortname register! class_eval(&b) if b end end |
.matches?(other) ⇒ Boolean
29 30 31 |
# File 'lib/rouge/token.rb', line 29 def matches?(other) other.token_chain.include? self end |
.qualname ⇒ Object
37 38 39 |
# File 'lib/rouge/token.rb', line 37 def qualname @qualname ||= token_chain.map(&:name).join('.') end |
.register! ⇒ Object
41 42 43 44 |
# File 'lib/rouge/token.rb', line 41 def register! Token.cache[self.qualname] = self parent.sub_tokens[self.name] = self end |
.sub_tokens ⇒ Object
15 16 17 |
# File 'lib/rouge/token.rb', line 15 def sub_tokens @sub_tokens ||= {} end |
.token(name, shortname, &b) ⇒ Object
57 58 59 60 |
# File 'lib/rouge/token.rb', line 57 def token(name, shortname, &b) tok = make_token(name, shortname, &b) const_set(name, tok) end |
.token_chain ⇒ Object
33 34 35 |
# File 'lib/rouge/token.rb', line 33 def token_chain @token_chain ||= ancestors.take_while { |x| x != Token }.reverse end |