130: def pathmap(spec=nil, &block)
131: return self if spec.nil?
132: result = ''
133: spec.scan(/%\{[^}]*\}-?\d*[sdpfnxX%]|%-?\d+d|%.|[^%]+/) do |frag|
134: case frag
135: when '%f'
136: result << File.basename(self)
137: when '%n'
138: result << File.basename(self).ext
139: when '%d'
140: result << File.dirname(self)
141: when '%x'
142: result << File.extname(self)
143: when '%X'
144: result << self.ext
145: when '%p'
146: result << self
147: when '%s'
148: result << (File::ALT_SEPARATOR || File::SEPARATOR)
149: when '%-'
150:
151: when '%%'
152: result << "%"
153: when /%(-?\d+)d/
154: result << pathmap_partial($1.to_i)
155: when /^%\{([^}]*)\}(\d*[dpfnxX])/
156: patterns, operator = $1, $2
157: result << pathmap('%' + operator).pathmap_replace(patterns, &block)
158: when /^%/
159: fail ArgumentError, "Unknown pathmap specifier #{frag} in '#{spec}'"
160: else
161: result << frag
162: end
163: end
164: result
165: end