class TokenString::Format
Public Instance Methods
convert_from(str)
click to toggle source
Convert an input string in this format to a token list and validate it
# File lib/token_string.rb, line 6 def convert_from str t = tokenize( str ).reject {|tok| tok == nil || tok.empty?} unless t.all?{|tok| validate(tok)} raise ArgumentError.new("Bad token in input: #{str.inspect} (tokens: #{t.inspect})") end t end
convert_to(tokens)
click to toggle source
Converts the tokens to this format.
# File lib/token_string.rb, line 15 def convert_to tokens join( tokens.map{|t| process(t.to_s) }) end
validate(token)
click to toggle source
Validate each token. For now its just to check if they are an identifier.
# File lib/token_string.rb, line 20 def validate token token =~ /[A-Za-z0-9]/ end