Class: Ciphr::Functions::Simple::Replace
Instance Attribute Summary
Attributes inherited from Function
#args, #options
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from Function
aligned, inherited, #initialize, invertable?, #prepend, #read
Class Method Details
.params ⇒ Object
117
118
119
|
# File 'lib/ciphr/functions/simple.rb', line 117
def self.params
[:input,:search,:replace]
end
|
.variants ⇒ Object
113
114
115
|
# File 'lib/ciphr/functions/simple.rb', line 113
def self.variants
[ [['repl','replace'], {}] ]
end
|
Instance Method Details
#apply ⇒ Object
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
|
# File 'lib/ciphr/functions/simple.rb', line 79
def apply
input, searchin, replacein = @args
search, replace = [searchin.read, replacein.read]
buf = ""
Proc.new do
if buf.size == search.size && search.size > 0
buf = ""
replace
else
inchunk = input.read(1)
if inchunk
if inchunk == search[buf.size]
buf += inchunk
""
else
buf += inchunk
input.prepend(buf[1,buf.size])
ret = buf[0]
buf = ""
ret
end
else
if buf.size > 0
ret = buf
buf = ""
ret
else
nil
end
end
end
end
end
|