From 4866d6e22fd1ab6559f32e5d83b2abe5bf1bf69a Mon Sep 17 00:00:00 2001 From: Erik Hatcher Date: Thu, 26 Apr 2007 02:06:01 +0000 Subject: [PATCH] rename tab_delimited to just delimited and added splitter parameter allowing lines to be split on any regular expression git-svn-id: https://svn.apache.org/repos/asf/lucene/solr/trunk@532565 13f79535-47bb-0310-9956-ffa450edef68 --- ...delimited_file_source.rb => delimited_file_source.rb} | 9 +++++---- ...file_source_test.rb => delimited_file_source_test.rb} | 4 ++-- 2 files changed, 7 insertions(+), 6 deletions(-) rename client/ruby/solr-ruby/lib/solr/importer/{tab_delimited_file_source.rb => delimited_file_source.rb} (80%) rename client/ruby/solr-ruby/test/unit/{tab_delimited_file_source_test.rb => delimited_file_source_test.rb} (87%) diff --git a/client/ruby/solr-ruby/lib/solr/importer/tab_delimited_file_source.rb b/client/ruby/solr-ruby/lib/solr/importer/delimited_file_source.rb similarity index 80% rename from client/ruby/solr-ruby/lib/solr/importer/tab_delimited_file_source.rb rename to client/ruby/solr-ruby/lib/solr/importer/delimited_file_source.rb index cc369b6a919..70f226a2eb0 100755 --- a/client/ruby/solr-ruby/lib/solr/importer/tab_delimited_file_source.rb +++ b/client/ruby/solr-ruby/lib/solr/importer/delimited_file_source.rb @@ -13,19 +13,20 @@ # For files with the first line containing field names # Currently not designed for enormous files, as all lines are # read into an array -class Solr::Importer::TabDelimitedFileSource +class Solr::Importer::DelimitedFileSource include Enumerable - def initialize(filename) + def initialize(filename, splitter=/\t/) @filename = filename + @splitter = splitter end def each lines = IO.readlines(@filename) - headers = lines[0].split("\t").collect{|h| h.chomp} + headers = lines[0].split(@splitter).collect{|h| h.chomp} lines[1..-1].each do |line| - data = headers.zip(line.split("\t").collect{|s| s.chomp}) + data = headers.zip(line.split(@splitter).collect{|s| s.chomp}) def data.[](key) self.assoc(key.to_s)[1] end diff --git a/client/ruby/solr-ruby/test/unit/tab_delimited_file_source_test.rb b/client/ruby/solr-ruby/test/unit/delimited_file_source_test.rb similarity index 87% rename from client/ruby/solr-ruby/test/unit/tab_delimited_file_source_test.rb rename to client/ruby/solr-ruby/test/unit/delimited_file_source_test.rb index f1a20979933..bb52fcc11ab 100755 --- a/client/ruby/solr-ruby/test/unit/tab_delimited_file_source_test.rb +++ b/client/ruby/solr-ruby/test/unit/delimited_file_source_test.rb @@ -13,12 +13,12 @@ require 'solr' require 'test/unit' -class TabDelimitedFileSourceTest < Test::Unit::TestCase +class DelimitedFileSourceTest < Test::Unit::TestCase def test_load filename = File.expand_path(File.dirname(__FILE__)) + "/tab_delimited.txt" - source = Solr::Importer::TabDelimitedFileSource.new(filename) + source = Solr::Importer::DelimitedFileSource.new(filename,/\t/) assert_equal source.to_a.size, 1 source.each do |data|