Class: Apfel::Reader
- Inherits:
-
Object
- Object
- Apfel::Reader
- Defined in:
- lib/apfel/reader.rb
Overview
Class for reading in files and returning an array of its content
Class Method Summary collapse
-
.read(file) ⇒ Object
Reads in a file and returns an array consisting of each line of input cleaned of new line characters.
Class Method Details
.read(file) ⇒ Object
Reads in a file and returns an array consisting of each line of input cleaned of new line characters
6 7 8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/apfel/reader.rb', line 6 def self.read(file) File.open(file, 'r') do |f| content = f.read.force_encoding('UTF-8') # remove the BOM that can be found at char 0 in UTF8 strings files if content.chars.first == "\xEF\xBB\xBF".force_encoding('UTF-8') content.slice!(0) end content.each_line.inject([]) do |content_array, line| line.gsub!("\n","") content_array.push(line) end end end |