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