Class: PxIndex

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

Instance Method Summary collapse

Constructor Details

#initialize(raw_s = nil, debug: false, allsorted: false, indexsorted: false) ⇒ PxIndex

Returns a new instance of PxIndex.



12
13
14
15
16
17
18
19
# File 'lib/pxindex.rb', line 12

def initialize(raw_s=nil, debug: false, allsorted: false, indexsorted: false)

  @allsorted, @indexsorted = allsorted, indexsorted
  @debug = debug    
  
  read raw_s if raw_s

end

Instance Method Details

#import(s) ⇒ Object

Returns a PxIndexBuilder object which can build from am index or phrases



23
24
25
26
27
# File 'lib/pxindex.rb', line 23

def import(s)
  
  read(PxIndexBuilder.new(s, debug: @debug).to_s)
  
end

#parentObject



29
30
31
# File 'lib/pxindex.rb', line 29

def parent()
  @rs.first
end

#q?(s) ⇒ Boolean Also known as: query

Returns:

  • (Boolean)


33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/pxindex.rb', line 33

def q?(s)
  
  return @a.last if s == @s
  puts '@s : ' + @s.inspect if @debug
  puts 's: ' + s.inspect if @debug
  
  # @s is used to store the previous string input to compare it with 
  # the new string input
  
  if (s.length - @s.length).abs >= 1 or s[0..-2] != @s then
    
    @s = s      

    @rs = @px.records.flat_map(&:records)
    
    s2 = ''
    
    @a = s.chars.map do |x|

      s2 += x
      found = search_records(s2, @rs)
      
      break if not found
      found
      
    end

    return @a ? @a.last  : nil
    
  end

  return []

end

#to_pxObject



70
71
72
# File 'lib/pxindex.rb', line 70

def to_px()
  @px
end

#to_sObject



74
75
76
# File 'lib/pxindex.rb', line 74

def to_s()
  @raw_px
end