lib/endeca/document_collection.rb in endeca-1.3.8 vs lib/endeca/document_collection.rb in endeca-1.4.0
- old
+ new
@@ -16,11 +16,10 @@
# collection, (+documents+). In most cases a DocumentCollection can be used
# as if it were an array of Document objects. (Array delegation pattern
# borrowed from Rake::FileList)
class DocumentCollection
include Readers
- extend ClassToProc
attr_reader :raw
def initialize(raw, document_klass=Document)
@raw = raw
@document_klass = document_klass
@@ -57,13 +56,13 @@
end
# The internal collection of Document objects. Array methods are delegated here.
def documents
if @raw['Records']
- @documents ||= @raw['Records'].map(&@document_klass)
+ @documents ||= @raw['Records'].map{|record| @document_klass.new(record)}
elsif aggregate?
- @documents ||= @raw['AggrRecords'].map{|aggregate| aggregate['Records'].first}.map(&@document_klass)
+ @documents ||= @raw['AggrRecords'].map{|aggregate| aggregate['Records'].first}.map{|record| @document_klass.new(record)}
else
[]
end
end
@@ -71,15 +70,15 @@
@raw['AggrRecords'] ? true : false
end
# The collection of Refinement objects for the collection.
def refinements
- @refinements ||= (@raw['Refinements'] || []).map(&Refinement)
+ @refinements ||= (@raw['Refinements'] || []).map{|data| Refinement.new(data)}
end
# The collection of Breadcrumb objects for the collection.
def breadcrumbs
- @breadcrumbs ||= (@raw['Breadcrumbs'] || []).map(&Breadcrumb)
+ @breadcrumbs ||= (@raw['Breadcrumbs'] || []).map{|data| Breadcrumb.create(data)}
end
# Return the refinement by name
def refinement_by_name(name)
refinements.find{|ref| ref.name.downcase == name.downcase}