lib/fbo/file.rb in fbo-0.0.3 vs lib/fbo/file.rb in fbo-0.1.0

- old
+ new

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