Class: Elf::Utilities::OffsetTable

Inherits:
Object
  • Object
show all
Defined in:
lib/elf/utils/offsettable.rb

Defined Under Namespace

Classes: InvalidIndex

Instance Method Summary collapse

Constructor Details

#initialize(content, separator) ⇒ OffsetTable

Returns a new instance of OffsetTable.



29
30
31
32
# File 'lib/elf/utils/offsettable.rb', line 29

def initialize(content, separator)
  @content = content
  @separator = separator
end

Instance Method Details

#[](idx) ⇒ Object

Raises:



38
39
40
41
42
43
44
45
46
# File 'lib/elf/utils/offsettable.rb', line 38

def [](idx)
  raise InvalidIndex.new(idx, size) if idx >= size

  # find the first occurrence of the separator starting from the
  # given index
  endidx = @content.index(@separator, idx)

  return @content[idx..endidx].chomp(@separator)
end

#sizeObject



34
35
36
# File 'lib/elf/utils/offsettable.rb', line 34

def size
  @content.size
end