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.



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

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

Class Method Details

.detect(line, outfile) ⇒ Object



52
53
54
55
56
57
58
59
60
# File 'lib/intar/redirect.rb', line 52

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



65
66
67
# File 'lib/intar/redirect.rb', line 65

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