Method: Stupidedi::Reader::FileInput#drop

Defined in:
lib/stupidedi/reader/input/file_input.rb

#drop(n) ⇒ AbstractInput

Advance the cursor forward ‘n` elements

Parameters:

  • n (Integer)

    the number of elements to advance (‘n >= 0`)

Returns:



88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
# File 'lib/stupidedi/reader/input/file_input.rb', line 88

def drop(n)
  raise ArgumentError, "n must be positive" unless n >= 0

  @io.seek(@offset)
  prefix = @io.read(n)
  suffix = @io

  length = prefix.length
  count  = prefix.count("\n")

  column = unless count.zero?
             length - prefix.rindex("\n")
           else
             @column + length
           end

  copy(:offset => @offset + length,
       :line   => @line + count,
       :column => column,
       :size   => @size - length)
end