我有一个主要的解析方法,它由解析 html 文件的其他方法组成:
class Parser
  def self.parse(html)
    @data = Nokogiri.HTML(open(html))
    merged_hashes = {}
    array_of_hashes = [
      parse_title,
      parse_description,
      parse_related
    ]
    array_of_hashes.inject(merged_hashes,:update)
    return merged_hashes
  end
  def self.parse_title
    title_hash = {}
    title = @data.at_css('.featureProductInfo a')
    return title_hash if title.nil?
    title_hash[:title] = @data.at_css('.featureProductInfo a').text
    title_hash
  end
  .
  .
  .
所以我在 Rspec 中这样做:
require File.dirname(__FILE__) + '/parser.rb'
def html_starcraft
  File.open("amazon_starcraft.html")
end
describe ".parse_title (StarCraft)" do
  let(:title_hash) { Parser.parse html_starcraft } 
  it "scraps the featured product title" do
    expect(title_hash[:title]).to eq("StarCraft II: Wings of Liberty (Bradygames Signature Guides)")
  end
end
如您所见,我一次只解析一个文件。我怎样才能同时解析多个?比如说,解析文件夹中的所有文件?