Module: Token::Container

Included in:
CodeObject::Base
Defined in:
lib/token/container.rb

Instance Method Summary collapse

Instance Method Details

#add_token(tokenid, token) ⇒ Object #add_token(token) ⇒ Object



35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/token/container.rb', line 35

def add_token(tokenid_or_token, token=nil)     

  unless token.nil?
    tokenid = tokenid_or_token
  else
    tokenid = tokenid_or_token.token
    token = tokenid_or_token
  end
  
  @tokens[tokenid] ||= []
  @tokens[tokenid] << token
end

#initializeObject



7
8
9
10
# File 'lib/token/container.rb', line 7

def initialize
  super
  @tokens = {}
end

#process_token(tokenline) ⇒ Object

TODO:

only raise error, if config is set to whiny

then calls matching tokenhandler (if exists) with data in ‘this`-context



51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/token/container.rb', line 51

def process_token(tokenline)

  # try to find matching tokenklass for token i.e. Token::Token::ParamToken for :param
  begin
    camelcased = tokenline.token.to_s.capitalize.gsub(/_\w/){|w| w[1].capitalize}
    tokenklass = Token.const_get "#{camelcased}Token"
    instance_exec(tokenklass, tokenline.content, &(tokenklass.handler))
  rescue Exception => error
    raise NoTokenHandler.new("No Tokenhandler for: @#{tokenline.token}
This is no big deal. You can add your custom tokenhandler for @#{tokenline.token} by adding the following line to your included ruby-file:

Token::Handler.register :#{tokenline.token} # optionally add a tokenhandler or target-area (See documentation for more infos)

After this using '@#{tokenline.token}' in your documentation is no problem...\n\n" + error.message)
  end
end

#process_tokens(tokenlines) ⇒ Object

Plural version of #process_token



71
72
73
# File 'lib/token/container.rb', line 71

def process_tokens(tokenlines)
  tokenlines.each {|tokenline| process_token(tokenline) }
end

#token(tokenname) ⇒ Token

provides access to tokens, through token identifier

Examples:

obj.token :public
#=> #<struct Token::Handler::Token content=nil> 


20
21
22
# File 'lib/token/container.rb', line 20

def token(tokenname)
  @tokens[tokenname.to_sym]
end

#tokensHash<Symbol, Array<Token::Token>>



25
26
27
# File 'lib/token/container.rb', line 25

def tokens
  @tokens
end