Class: RIO::Piper::Base

Inherits:
Object show all
Defined in:
lib/rio/piper.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(r1, r2, *args) ⇒ Base

Returns a new instance of Base.



30
31
32
33
34
35
36
37
# File 'lib/rio/piper.rb', line 30

def initialize(r1,r2,*args)
  @rios = []
  add_arg(r1)
  add_arg(r2)
  args.each { |r|
    add_arg(r)
  }
end

Instance Attribute Details

#riosObject (readonly)

Returns the value of attribute rios.



29
30
31
# File 'lib/rio/piper.rb', line 29

def rios
  @rios
end

Instance Method Details

#add_arg(arg) ⇒ Object



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/rio/piper.rb', line 38

def add_arg(arg)
  case arg
  when Base
    @rios += arg.rios
  when Rio
    case arg.scheme
    when 'cmdpipe'
      arg_piper = arg.rl.piper
      @rios += arg_piper.rios
    else
      @rios << arg
    end
  else
    raise ArgumentError,"Argument (#{arg}) is a #{arg.class}, should be a Rio or a Piper"
  end
end

#has_output_dest?Boolean

Returns:

  • (Boolean)


58
59
60
61
62
63
# File 'lib/rio/piper.rb', line 58

def has_output_dest?
  case @rios[-1].scheme
  when 'cmdio' then false
  else true
  end
end

#initialize_copy(*args) ⇒ Object



54
55
56
57
# File 'lib/rio/piper.rb', line 54

def initialize_copy(*args)
  super
  @rios = @rios.map{ |r| r.clone }
end

#new_with(*args) ⇒ Object



64
65
66
67
68
69
70
# File 'lib/rio/piper.rb', line 64

def new_with(*args)
  cp = self.clone
  args.each { |r|
    cp.push(r)
  }
  cp
end

#push(r) ⇒ Object



71
72
73
# File 'lib/rio/piper.rb', line 71

def push(r)
  @rios << r
end

#rdObject



79
# File 'lib/rio/piper.rb', line 79

def rd() @rios[-1] end

#runObject



82
83
84
85
86
87
88
89
90
# File 'lib/rio/piper.rb', line 82

def run
  dups = @rios
  (1...dups.size-1).each { |i| dups[i].w! }
  (1...dups.size).each { |i|
    dups[i-1] > dups[i]
  }
  dups.each { |r| r.close.softreset }
  dups[-1]
end

#run_to(r) ⇒ Object



74
75
76
77
78
# File 'lib/rio/piper.rb', line 74

def run_to(r)
  @rios << r
  run
  self
end

#wrObject



80
# File 'lib/rio/piper.rb', line 80

def wr() @rios[0] end