Class: TagAlong::Offsets

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/tag_along/offsets.rb

Instance Method Summary collapse

Constructor Details

#initialize(offsets, opts = {}) ⇒ Offsets

Returns a new instance of Offsets.



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/tag_along/offsets.rb', line 6

def initialize(offsets, opts = {})

  @offsets      = offsets
  @offset_start = (opts[:offset_start] || 'offset_start').to_sym
  @offset_end   = (opts[:offset_end]   || 'offset_end').to_sym
  @data_start   = (opts[:data_start]   || 'data_start').to_sym
  @data_end     = (opts[:data_end]     || 'data_end').to_sym

  item = @offsets.first
  if item.is_a?(Array)
    process_array
  elsif item.is_a?(Hash)
    process_hash
  else
    process_obj
  end
  @offsets.sort_by!(&:offset_start)
end

Instance Method Details

#<<(offset) ⇒ Object



43
44
45
46
47
48
# File 'lib/tag_along/offsets.rb', line 43

def << offset
  unless offset.respond_to?(:offset_start) && offset.respond_to?(:offset_end)
    raise TypeError.new('Object does not match Offset signature')
  end
  @offsets << offset
end

#[](num) ⇒ Object



31
32
33
# File 'lib/tag_along/offsets.rb', line 31

def [](num)
  @offsets[num]
end

#each(&block) ⇒ Object



25
26
27
28
29
# File 'lib/tag_along/offsets.rb', line 25

def each(&block)
  @offsets.each do |o|
    block.call(o)
  end
end

#empty?Boolean

Returns:

  • (Boolean)


39
40
41
# File 'lib/tag_along/offsets.rb', line 39

def empty?
  @offsets.empty?
end

#shiftObject



35
36
37
# File 'lib/tag_along/offsets.rb', line 35

def shift
  @offsets.shift
end