Class: TaskJuggler::TextParser::Scanner::FileStreamHandle

Inherits:
StreamHandle show all
Defined in:
lib/taskjuggler/TextParser/Scanner.rb

Overview

Specialized version of StreamHandle for operations on files.

Instance Attribute Summary collapse

Attributes inherited from StreamHandle

#macroStack

Instance Method Summary collapse

Methods inherited from StreamHandle

#cleanupMacroStack, #dirname, #eof?, #error, #injectMacro, #injectText, #line, #lineNo, #peek, #readyNextLine, #scan

Constructor Details

#initialize(fileName, log, textScanner) ⇒ FileStreamHandle

Returns a new instance of FileStreamHandle.



171
172
173
174
175
176
177
178
179
180
181
182
# File 'lib/taskjuggler/TextParser/Scanner.rb', line 171

def initialize(fileName, log, textScanner)
  super(log, textScanner)
  @fileName = fileName.dup
  data = (fileName == '.' ? $stdin : File.new(@fileName, 'r')).read
  begin
    @stream = StringIO.new(data.forceUTF8Encoding)
  rescue
    error('fileEncoding', $!.message)
  end
  @log.msg { "Parsing file #{@fileName} ..." }
  @log.startProgressMeter("Reading file #{fileName}")
end

Instance Attribute Details

#fileNameObject (readonly)

Returns the value of attribute fileName.



169
170
171
# File 'lib/taskjuggler/TextParser/Scanner.rb', line 169

def fileName
  @fileName
end

Instance Method Details

#closeObject



184
185
186
187
# File 'lib/taskjuggler/TextParser/Scanner.rb', line 184

def close
  @stream.close unless @stream == $stdin
  super
end