24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
|
# File 'lib/patter/pattern.rb', line 24
def to_s
@pattern.gsub(/\{([#{TAGS.keys.join}])(:(\w+))?\}/) do
tag = $1
modifiers = $3
source = @source_provider.get_source(TAGS[tag])
next source.get_sample if !modifiers
re = /([#{MODIFIERS.keys.join}])|([0-9]+)/
chain = []
n = 1
modifiers.split(re).reject(&:empty?).each do |modifier|
if modifier =~ /([0-9]+)/
n = $1.to_i
end
if MODIFIERS[modifier]
chain << MODIFIERS[modifier]
end
end
source.get_samples(n).map do |sample|
sample.transform(chain)
end.join
end
end
|