blob: 35170d8b21fd1873a5930b56a0a6d131840166be (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
|
module Guff
class TemplateToken
getter :type
getter :value
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: %s" % [@value] unless args.has_key?(@value)
args[@value]
when :val
@value
else
# never reached
raise "unknown token type: %s" % [@type]
end
end
end
end
|