Class: Indexer101::Index

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeIndex

Returns a new instance of Index.



20
21
22
23
24
25
26
# File 'lib/indexer101.rb', line 20

def initialize()          

  @uri_index = {} # contains each URI long with the title
  @index = {} # contains eack keyword
  @h = {} # nested keywords constructed from shared string keys

end

Instance Attribute Details

#hObject (readonly)

Returns the value of attribute h.



17
18
19
# File 'lib/indexer101.rb', line 17

def h
  @h
end

#indexObject

Returns the value of attribute index.



18
19
20
# File 'lib/indexer101.rb', line 18

def index
  @index
end

#uri_indexObject

Returns the value of attribute uri_index.



18
19
20
# File 'lib/indexer101.rb', line 18

def uri_index
  @uri_index
end

Instance Method Details

#build(a) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/indexer101.rb', line 28

def build(a)
  
  threads = []
  
  if @index.empty? then
    threads << Thread.new do
      @index = Hash[a.map(&:to_sym).zip([''] * a.length)]
    end
  end
  
  threads << Thread.new { @h = group a }
  ThreadsWait.all_waits(*threads)      
        
end

#inspectObject



43
44
45
46
# File 'lib/indexer101.rb', line 43

def inspect()
  h = @h ? @h.inspect[0..30] + "..." : nil
  "#<Indexer101::Index @h=#{h.inspect}>"
end