问题描述
正在尝试构建一个 pptx 到 scorm 转换器。我收到一个错误 NoMethodError Undefined method `+' for NilClass。我想这可能是由于一个定义的方法。关于如何消除此错误的任何想法?
dir = ARGV.shift
dest = ARGV.shift
pptx = dir + "/presentation.pptx"
lis = []`enter code here`
STDERR.puts "Copy template => #{dest}"
FileUtils.cp_r "template",dest
Dir["#{dir}/*.PNG"].each do |file|
STDERR.puts "Copy #{file} => #{dest}/img"
FileUtils.cp file,"#{dest}/img/"
STDERR.puts "Creating thumb #{file} => #{dest}/img/thumb"
name = file.split(/\//).last
system "/usr/bin/convert","-scale","200x",file,"#{dest}/img/thumb/#{name}"
lis.push name
end
ordered = lis.sort_by { |x| x[/\d+/].to_i }
解决方法
DIR 为零
如果您按如下方式调试代码:
puts dir.nil? # true
因此,为了运行此代码,您必须为 ruby shell 提供 2 个参数,如下所示:
ruby test.rb DIRECTORY_NAME DESTINATION_NAME