Class: OCR::Factory

Inherits:
Object
  • Object
show all
Defined in:
lib/ocr/factory.rb

Direct Known Subclasses

Ocr

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ Factory

Returns a new instance of Factory.



9
10
11
# File 'lib/ocr/factory.rb', line 9

def initialize(*args)
  self.init(*args) if self.respond_to?(:init)
end

Instance Attribute Details

#argsObject (readonly)

Returns the value of attribute args.



3
4
5
# File 'lib/ocr/factory.rb', line 3

def args
  @args
end

Class Method Details

.create(type = self.class, *args) ⇒ Object

Raises:

  • (ArgumentError)


13
14
15
16
17
18
19
20
21
# File 'lib/ocr/factory.rb', line 13

def self.create(type = self.class, *args)
  raise ArgumentError, "Cannot create instance of #{type} from #{self.name}" if type == self
  raise ArgumentError, "Type cannot be nil" if type.nil?

  if !type.ancestors.include?(self)
    raise ArgumentError, "#{type.name} is not a descendant of #{self.name}"
  end
  type.new(*args)
end