Class: Recls::FileSearchLineEnumerator

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/recls/foreach.rb

Overview

:nodoc: all

Instance Method Summary collapse

Constructor Details

#initialize(fs) ⇒ FileSearchLineEnumerator

Returns a new instance of FileSearchLineEnumerator.



53
54
55
56
# File 'lib/recls/foreach.rb', line 53

def initialize(fs)

  @fs = fs
end

Instance Method Details

#each(&block) ⇒ Object



58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/recls/foreach.rb', line 58

def each(&block)

  @fs.each do |fe|

    IO.readlines(fe).each_with_index do |line, index|

      case block.arity
      when 1
        yield line
      when 2
        yield line, index
      when 3
        yield line, index, fe
      else
        raise ArgumentError, "block must take 1, 2, or 3 parameters - #{block.arity} given. (Perhaps you have applied each_with_index, which cannot be done to Recls.foreach)"
      end
    end
  end
end