# File lib/rake.rb, line 202
202:     def pathmap(spec=nil, &block)
203:       return self if spec.nil?
204:       result = ''
205:       spec.scan(/%\{[^}]*\}-?\d*[sdpfnxX%]|%-?\d+d|%.|[^%]+/) do |frag|
206:         case frag
207:         when '%f'
208:           result << File.basename(self)
209:         when '%n'
210:           result << File.basename(self).ext
211:         when '%d'
212:           result << File.dirname(self)
213:         when '%x'
214:           result << $1 if self =~ /[^\/](\.[^.]+)$/
215:         when '%X'
216:           if self =~ /^(.+[^\/])(\.[^.]+)$/
217:             result << $1
218:           else
219:             result << self
220:           end
221:         when '%p'
222:           result << self
223:         when '%s'
224:           result << (File::ALT_SEPARATOR || File::SEPARATOR)
225:         when '%-'
226:           # do nothing
227:         when '%%'
228:           result << "%"
229:         when /%(-?\d+)d/
230:           result << pathmap_partial($1.to_i)
231:         when /^%\{([^}]*)\}(\d*[dpfnxX])/
232:           patterns, operator = $1, $2
233:           result << pathmap('%' + operator).pathmap_replace(patterns, &block)
234:         when /^%/
235:           fail ArgumentError, "Unknown pathmap specifier #{frag} in '#{spec}'"
236:         else
237:           result << frag
238:         end
239:       end
240:       result
241:     end