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.
6 7 8 |
# File 'lib/rouge/token.rb', line 6 def name @name end |
.parent ⇒ Object (readonly)
Returns the value of attribute parent.
7 8 9 |
# File 'lib/rouge/token.rb', line 7 def parent @parent end |
.shortname ⇒ Object (readonly)
Returns the value of attribute shortname.
8 9 10 |
# File 'lib/rouge/token.rb', line 8 def shortname @shortname end |
Class Method Details
.[](qualname) ⇒ Object
18 19 20 21 22 |
# File 'lib/rouge/token.rb', line 18 def [](qualname) return qualname unless qualname.is_a? ::String Token.cache[qualname] end |
.cache ⇒ Object
10 11 12 |
# File 'lib/rouge/token.rb', line 10 def cache @cache ||= {} end |
.each_token(&b) ⇒ Object
61 62 63 64 65 |
# File 'lib/rouge/token.rb', line 61 def each_token(&b) Token.cache.each do |(_, t)| b.call(t) end end |
.inspect ⇒ Object
24 25 26 |
# File 'lib/rouge/token.rb', line 24 def inspect "<Token #{qualname}>" end |
.make_token(name, shortname, &b) ⇒ Object
45 46 47 48 49 50 51 52 53 54 |
# File 'lib/rouge/token.rb', line 45 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
28 29 30 |
# File 'lib/rouge/token.rb', line 28 def matches?(other) other.token_chain.include? self end |
.qualname ⇒ Object
36 37 38 |
# File 'lib/rouge/token.rb', line 36 def qualname @qualname ||= token_chain.map(&:name).join('.') end |
.register! ⇒ Object
40 41 42 43 |
# File 'lib/rouge/token.rb', line 40 def register! Token.cache[self.qualname] = self parent.sub_tokens[self.name] = self end |
.sub_tokens ⇒ Object
14 15 16 |
# File 'lib/rouge/token.rb', line 14 def sub_tokens @sub_tokens ||= {} end |
.token(name, shortname, &b) ⇒ Object
56 57 58 59 |
# File 'lib/rouge/token.rb', line 56 def token(name, shortname, &b) tok = make_token(name, shortname, &b) const_set(name, tok) end |
.token_chain ⇒ Object
32 33 34 |
# File 'lib/rouge/token.rb', line 32 def token_chain @token_chain ||= ancestors.take_while { |x| x != Token }.reverse end |