Class: Intar::RedirectFile

Inherits:
Redirect show all
Defined in:
lib/intar/redirect.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Redirect

#redirect_output

Constructor Details

#initialize(path, append) ⇒ RedirectFile

Returns a new instance of RedirectFile.



58
59
60
# File 'lib/intar/redirect.rb', line 58

def initialize path, append
  @path, @append = path, append
end

Class Method Details

.detect(line, outfile) ⇒ Object



48
49
50
51
52
53
54
55
56
# File 'lib/intar/redirect.rb', line 48

def detect line, outfile
  if line.slice! /\s+>(>)?(\S+|"((?:[^\\"]|\\.)*)")\z/ then
    p = $3 ? ($3.gsub /\\(.)/, "\\1") : $2
    append = true if $1
    new p, append
  elsif outfile then
    new outfile.to_s, true
  end
end

Instance Method Details

#outfileObject



61
62
63
# File 'lib/intar/redirect.rb', line 61

def outfile
  File.open @path, (@append ? "a" : "w") rescue raise Failed, "File error: #$!"
end