diff options
Diffstat (limited to 'src/guff/template-token.cr')
-rw-r--r-- | src/guff/template-token.cr | 14 |
1 files changed, 9 insertions, 5 deletions
diff --git a/src/guff/template-token.cr b/src/guff/template-token.cr index 04e8f11..35170d8 100644 --- a/src/guff/template-token.cr +++ b/src/guff/template-token.cr @@ -1,20 +1,24 @@ module Guff class TemplateToken getter :type + getter :value - def initialize(@type : Symbol, @val : String) + TOKEN_TYPES = %i{key val} + + def initialize(@type : Symbol, @value : String) + raise "invalid type: %s" % [@type] unless TOKEN_TYPES.includes?(@type) end def get(args : Hash(String, String)) case @type when :key - raise "missing key: #{@val}" unless args.has_key?(@val) - args[@val] + raise "missing key: %s" % [@value] unless args.has_key?(@value) + args[@value] when :val - @val + @value else # never reached - raise "unknown token type: #{@type}" + raise "unknown token type: %s" % [@type] end end end |