Class: Endeca::Factory

Inherits:
Object show all
Defined in:
lib/endeca_factory.rb

Overview

Endeca::Factory creates stubbed Endeca objects. It expects a hash (or array of hashes) and the class of the Document object(s) to be created.

Constant Summary collapse

VERSION =

:nodoc:

"0.4.0"

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(params, klass) ⇒ Factory

:nodoc:



17
18
19
20
21
22
23
24
25
# File 'lib/endeca_factory.rb', line 17

def initialize(params, klass) #:nodoc:
  params = params.dup
  @klass = klass
  case params
  when Hash; @objects = build_from_hash(params)
  when Array; @objects = build_from_array(params)
  else; raise ArgumentError, "Unable to build a(n) #{klass.name} from #{objects.inspect}"
  end
end

Instance Attribute Details

#objectsObject (readonly)

:nodoc:



15
16
17
# File 'lib/endeca_factory.rb', line 15

def objects
  @objects
end

Class Method Details

.create(params, klass) ⇒ Object

Creates stubbed Endeca::Document and Endeca::DocumentCollection objects. Pass a hash to return a single stubbed Endeca::Document object or an array of hashes to return an Endeca::DocumentCollection object with documents stubbed to return the collection of documents built from the array of hashes.

Example:

Endeca::Factory.create({:title => "A Title"}, Listing)


35
36
37
# File 'lib/endeca_factory.rb', line 35

def self.create(params, klass)
  new(params, klass).objects
end

.versionObject

:nodoc:



10
11
12
# File 'lib/endeca_factory.rb', line 10

def self.version #:nodoc:
  VERSION
end