Class: StringOutput

Inherits:
Object show all
Defined in:
lib/tmail/stringio.rb

Overview

:nodoc:

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(str = '') ⇒ StringOutput

Returns a new instance of StringOutput.


197
198
199
200
# File 'lib/tmail/stringio.rb', line 197

def initialize( str = '' )
  @dest = str
  @closed = false
end

Class Method Details

.new(str = '') ⇒ Object Also known as: open


180
181
182
183
184
185
186
187
188
189
190
191
# File 'lib/tmail/stringio.rb', line 180

def new( str = '' )
  if block_given?
    begin
      f = super
      yield f
    ensure
      f.close if f
    end
  else
    super
  end
end

Instance Method Details

#<<(str) ⇒ Object


268
269
270
271
272
# File 'lib/tmail/stringio.rb', line 268

def <<( str )
  stream_check!
  @dest << str.to_s
  self
end

#closeObject


202
203
204
# File 'lib/tmail/stringio.rb', line 202

def close
  @closed = true
end

#closed?Boolean

Returns:

  • (Boolean)

206
207
208
# File 'lib/tmail/stringio.rb', line 206

def closed?
  @closed
end

#inspectObject


223
224
225
# File 'lib/tmail/stringio.rb', line 223

def inspect
  "#<#{self.class}:#{@dest ? 'open' : 'closed'},#{object_id}>"
end

Raises:

  • (ArgumentError)

227
228
229
230
231
232
233
234
235
# File 'lib/tmail/stringio.rb', line 227

def print( *args )
  stream_check!
  raise ArgumentError, 'wrong # of argument (0 for >1)' if args.empty?
  args.each do |s|
    raise ArgumentError, 'nil not allowed' if s.nil?
    @dest << s.to_s
  end
  nil
end

#printf(*args) ⇒ Object


253
254
255
256
257
# File 'lib/tmail/stringio.rb', line 253

def printf( *args )
  stream_check!
  @dest << sprintf(*args)
  nil
end

#putc(ch) ⇒ Object


247
248
249
250
251
# File 'lib/tmail/stringio.rb', line 247

def putc( ch )
  stream_check!
  @dest << ch.chr
  nil
end

#puts(*args) ⇒ Object


237
238
239
240
241
242
243
244
245
# File 'lib/tmail/stringio.rb', line 237

def puts( *args )
  stream_check!
  args.each do |str|
    @dest << (s = str.to_s)
    @dest << "\n" unless s[-1] == ?\n
  end
  @dest << "\n" if args.empty?
  nil
end

#sizeObject Also known as: pos


217
218
219
# File 'lib/tmail/stringio.rb', line 217

def size
  @dest.size
end

#stringObject Also known as: value, to_str


210
211
212
# File 'lib/tmail/stringio.rb', line 210

def string
  @dest
end

#write(str) ⇒ Object Also known as: syswrite


259
260
261
262
263
264
# File 'lib/tmail/stringio.rb', line 259

def write( str )
  stream_check!
  s = str.to_s
  @dest << s
  s.size
end