30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
|
# File 'lib/mustermann/ast/param_scanner.rb', line 30
def converter(capture)
case capture
when Hash then return converter(capture[name.to_sym])
when Class then regexp, converter = CONVERTERS[capture.name]
when Symbol then regexp, converter = CONVERTERS[capture]
when Array
entries = capture.map { |item| converter(item) }.compact
regexp = Regexp.union(entries.map(&:first))
entries.map! { |r, c| [/\A#{r}\Z/, c] }
converter = ->(string) do
_, c = entries.find { |r, _| r.match?(string) }
c&.call(string) || string
end
end
return unless converter
[regexp, converter.to_proc]
end
|