refactor Document slightly, allowing << to take multiple fields in a Hash

git-svn-id: https://svn.apache.org/repos/asf/incubator/solr/trunk@495837 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Erik Hatcher 2007-01-13 04:31:47 +00:00
parent 01c454c9a2
commit c20a0cc4d8
1 changed files with 5 additions and 5 deletions

View File

@ -23,7 +23,7 @@ module Solr
# doc = Solr::Document.new(:creator => 'Jorge Luis Borges')
def initialize(hash={})
@fields = []
hash.each_pair {|k,v| @fields << Solr::Field.new(k => v)}
self << hash
end
# Append a Solr::Field
@ -33,12 +33,12 @@ module Solr
# If you are truly lazy you can simply pass in a hash:
#
# doc << {:creator => 'Jorge Luis Borges'}
def <<(field)
case field
def <<(fields)
case fields
when Hash
@fields << Solr::Field.new(field)
fields.each_pair {|k,v| @fields << Solr::Field.new(k => v)}
when Solr::Field
@fields << field
@fields << fields
else
raise "must pass in Solr::Field or Hash"
end