Class: CharDetector::Engine

Inherits:
Object
  • Object
show all
Defined in:
lib/char_detector/engine.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(file:) ⇒ Engine

Returns a new instance of Engine.



3
4
5
# File 'lib/char_detector/engine.rb', line 3

def initialize(file:)
  @file = file
end

Instance Attribute Details

#fileObject (readonly)

Returns the value of attribute file.



7
8
9
# File 'lib/char_detector/engine.rb', line 7

def file
  @file
end

Instance Method Details

#scanObject



9
10
11
12
13
14
15
16
17
18
19
# File 'lib/char_detector/engine.rb', line 9

def scan
  matches = []

  File.readlines(file).each_with_index do |line, index|
    if result = Line.new(index+1, line, /\p{Cntrl}/).scanline
      matches << result
    end
  end

  return matches
end