Method: Cog::Helpers::FileScanner.scan

Defined in:
lib/cog/helpers/file_scanner.rb

.scan(filename, pattern, opt = {}) {|scanner| ... } ⇒ Object?

Opens the given file for scanning.

Parameters:

  • filename (String)

    path to the file which will be scanned

  • pattern (Regexp)

    a pattern to test for

  • opt (Hash) (defaults to: {})

    a customizable set of options

Options Hash (opt):

  • :occurrence (Fixnum) — default: 0

    0 for the first, 1 for the second, and so on

Yield Parameters:

Yield Returns:

  • (Object)

Returns:

  • (Object, nil)

    the return value of the block, or nil if the pattern was not found



51
52
53
54
55
56
57
58
59
60
# File 'lib/cog/helpers/file_scanner.rb', line 51

def self.scan(filename, pattern, opt={}, &block)
  s = new filename
  val = if s.read_until pattern, opt[:occurrence] || 0
    block.call s
  else
    nil
  end
  s.close
  val
end