It appears as if you have a parenthesis misplaced, this line:
File.open (File.basename("#{LOCAL_DIR}/#{image}", 'w')) do |f|
Should be this:
File.open(File.basename("#{LOCAL_DIR}/#{image}"), 'w') do |f|
But actually, on further investigation of your code, it appears that File.basename is acting on the incorrect string in this situation. After getting your code to run, it filled the root folder of scraper.rb with images. So, what I think you really want for that line is this:
#only grab the basename of the image, then concatenate that to the end of the local_dir:
filename = "#{LOCAL_DIR}/#{File.basename(image)}"
File.open(filename, 'w') do |f|
After running this, I got to the next problem. It appears as though 'image' is an array which contains many urls.
Depending on what you are trying to achieve, you may need to do some additional filtering to get the image down to a single image, or change it to 'images' and have the following code:
images = imagelink.map { |link| link['href'] }
images.each do |image|
File.open(File.basename("#{LOCAL_DIR}/#{image}"), 'w') do |f|
f.write(open(image).read)
end
end
@row = @row + 1