17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
|
# File 'lib/phlexi/field/common/tokens.rb', line 17
def tokens(*tokens, **conditional_tokens)
conditional_tokens.each do |condition, token|
truthy = case condition
when Symbol then send(condition)
when Proc then condition.call
else raise ArgumentError, "The class condition must be a Symbol or a Proc."
end
if truthy
case token
when Hash then __append_token__(tokens, token[:then])
else __append_token__(tokens, token)
end
else
case token
when Hash then __append_token__(tokens, token[:else])
end
end
end
tokens = tokens.select(&:itself).join(" ")
tokens.strip!
tokens.gsub!(/\s+/, " ")
tokens
end
|