lib/fbo/file.rb in fbo-0.1.2 vs lib/fbo/file.rb in fbo-0.1.3

- old
+ new

@@ -3,11 +3,11 @@ module FBO class File extend Forwardable attr_reader :file - def_delegators :@file, :readline, :read, :eof?, :gets + def_delegators :@file, :eof?, :eof class << self def filename_for_date(date) raise ArgumentError, "No date given for file" unless date "FBOFeed#{ date.strftime("%Y%m%d") }" @@ -16,17 +16,22 @@ def initialize(filename) @file = ::File.new(filename) end + def gets + str = @file.gets + str.nil? ? nil : cleanup_data(str) + end + def contents if @contents.nil? @contents = cleanup_data(@file.read) end @contents end - private + protected def cleanup_data(data) data.encode('UTF-16le', :invalid => :replace, :replace => '') .encode('UTF-8') .gsub(/\r\n/, "\n")