Class: Rubygrep::FileReader
- Inherits:
-
Object
- Object
- Rubygrep::FileReader
- Defined in:
- lib/rubygrep/file_reader.rb
Instance Attribute Summary collapse
-
#file_names ⇒ Object
Returns the value of attribute file_names.
-
#options ⇒ Object
Returns the value of attribute options.
-
#skip_current_file ⇒ Object
Returns the value of attribute skip_current_file.
Instance Method Summary collapse
- #each_line ⇒ Object
- #has_several_files? ⇒ Boolean
-
#initialize(file_names, options = {}) ⇒ FileReader
constructor
A new instance of FileReader.
- #next_file! ⇒ Object
Constructor Details
#initialize(file_names, options = {}) ⇒ FileReader
Returns a new instance of FileReader.
6 7 8 9 |
# File 'lib/rubygrep/file_reader.rb', line 6 def initialize(file_names, = {}) @options = @file_names = FileSearcher.new().search(file_names) end |
Instance Attribute Details
#file_names ⇒ Object
Returns the value of attribute file_names.
4 5 6 |
# File 'lib/rubygrep/file_reader.rb', line 4 def file_names @file_names end |
#options ⇒ Object
Returns the value of attribute options.
4 5 6 |
# File 'lib/rubygrep/file_reader.rb', line 4 def @options end |
#skip_current_file ⇒ Object
Returns the value of attribute skip_current_file.
4 5 6 |
# File 'lib/rubygrep/file_reader.rb', line 4 def skip_current_file @skip_current_file end |
Instance Method Details
#each_line ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/rubygrep/file_reader.rb', line 15 def each_line file_names.each do |file_name| next_file = open_file(file_name) num = 0 if next_file next_file.each_line do |str| str = str.encode("UTF-16be", :invalid=>:replace, :replace=>"").encode('UTF-8') unless str.valid_encoding? yield({str: str, path: file_name, str_num: num+=1}) if skip_current_file @skip_current_file = false break end end end end end |
#has_several_files? ⇒ Boolean
11 12 13 |
# File 'lib/rubygrep/file_reader.rb', line 11 def has_several_files? file_names.length > 1 end |
#next_file! ⇒ Object
32 33 34 |
# File 'lib/rubygrep/file_reader.rb', line 32 def next_file! @skip_current_file = true end |