Class: Epos::IndexFile

Inherits:
Object
  • Object
show all
Defined in:
lib/epos/index-file.rb

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ IndexFile

Returns a new instance of IndexFile.



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/epos/index-file.rb', line 6

def initialize(path)
  data = EncodedFile.read(path)
  lines = data.lines
  @index = {}
  lines.each do |line|
    i = line.index(";")
    key = line[0..i - 1]
    val = line[i + 1..-2].to_i
    if @index.has_key?(key)
      @index[key] << val
    else
      @index[key] = [val]
    end
  end
end

Instance Method Details

#has_key?(key) ⇒ Boolean

Returns:

  • (Boolean)


30
31
32
# File 'lib/epos/index-file.rb', line 30

def has_key?(key)
  @index.has_key?(key)
end

#keysObject



26
27
28
# File 'lib/epos/index-file.rb', line 26

def keys
  return @index.keys
end

#look_up(key) ⇒ Object



22
23
24
# File 'lib/epos/index-file.rb', line 22

def look_up(key)
  return @index[key] || []
end