Class: Epos::IndexFile
- Inherits:
-
Object
- Object
- Epos::IndexFile
- Defined in:
- lib/epos/index-file.rb
Instance Method Summary collapse
- #has_key?(key) ⇒ Boolean
-
#initialize(path) ⇒ IndexFile
constructor
A new instance of IndexFile.
- #keys ⇒ Object
- #look_up(key) ⇒ Object
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
30 31 32 |
# File 'lib/epos/index-file.rb', line 30 def has_key?(key) @index.has_key?(key) end |
#keys ⇒ Object
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 |