Module: OnlyofficeFileHelper::ReadMethods
- Included in:
- FileHelper
- Defined in:
- lib/onlyoffice_file_helper/read_methods.rb
Overview
Methods used to read something
Instance Method Summary collapse
- #read_array_from_file(file_name) ⇒ Object
- #read_file_to_string(file_name) ⇒ Object
-
#read_specific_line(file_name, line_number) ⇒ String
Get line count in file.
Instance Method Details
#read_array_from_file(file_name) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/onlyoffice_file_helper/read_methods.rb', line 18 def read_array_from_file(file_name) result_array = [] return [] unless File.exist?(file_name) File.open(file_name, 'r') do |infile| while (line = infile.gets) result_array << line.sub("\n", '') end end result_array end |
#read_file_to_string(file_name) ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 |
# File 'lib/onlyoffice_file_helper/read_methods.rb', line 6 def read_file_to_string(file_name) result_string = '' raise 'File not found: ' + file_name.to_s unless File.exist?(file_name) File.open(file_name, 'r') do |infile| while (line = infile.gets) result_string += line end end result_string end |
#read_specific_line(file_name, line_number) ⇒ String
Get line count in file
34 35 36 37 38 39 |
# File 'lib/onlyoffice_file_helper/read_methods.rb', line 34 def read_specific_line(file_name, line_number) line = `sed '#{line_number + 1}!d' #{file_name}` line.chop! if line[-1] == "\n" OnlyofficeLoggerHelper.log("Lines in '#{file_name}' by number is '#{line}'") line end |