Class: IndexableFactory

Inherits:
Object show all
Defined in:
lib/rpdf2txt-rockit/indexable.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(klass, startIndex = 0) ⇒ IndexableFactory

Returns a new instance of IndexableFactory.



9
10
11
12
13
14
15
# File 'lib/rpdf2txt-rockit/indexable.rb', line 9

def initialize(klass, startIndex = 0)
  unless klass.ancestors.include?(Indexable)
    raise ArgumentError, "#{klass.inspect} is not Indexable" 
  end
  @klass, @start_index, @next_index = klass, startIndex, startIndex
  @instance_map, @instances = Hash.new, Array.new
end

Instance Attribute Details

#instancesObject (readonly)

Returns the value of attribute instances.



7
8
9
# File 'lib/rpdf2txt-rockit/indexable.rb', line 7

def instances
  @instances
end

#next_indexObject (readonly)

Returns the value of attribute next_index.



7
8
9
# File 'lib/rpdf2txt-rockit/indexable.rb', line 7

def next_index
  @next_index
end

#start_indexObject (readonly)

Returns the value of attribute start_index.



7
8
9
# File 'lib/rpdf2txt-rockit/indexable.rb', line 7

def start_index
  @start_index
end

Instance Method Details

#get_instance(*args) ⇒ Object



31
32
33
# File 'lib/rpdf2txt-rockit/indexable.rb', line 31

def get_instance(*args)
  @instance_map[args]
end

#instance_with_args(*args) ⇒ Object



35
36
37
# File 'lib/rpdf2txt-rockit/indexable.rb', line 35

def instance_with_args(*args)
  @instance_map[args] || (@instance_map[args] = make(*args))
end

#make(*args) ⇒ Object



17
18
19
20
21
22
23
24
# File 'lib/rpdf2txt-rockit/indexable.rb', line 17

def make(*args)
  obj = @instance_map[args]
  unless obj
    @instance_map[args] = obj = make_new_obj(args)
    @instances.push obj
  end
  obj
end

#make_unless_exists(*args) ⇒ Object



26
27
28
29
# File 'lib/rpdf2txt-rockit/indexable.rb', line 26

def make_unless_exists(*args)
  new_instance = @instance_map[args] == nil
  return make(*args), new_instance
end