Class: Peruby::IOHandle

Inherits:
Object
  • Object
show all
Defined in:
lib/peruby/runtime/io_handle.rb

Overview

Perl filehandle state over a Ruby IO object.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(io, layers: []) ⇒ IOHandle

Returns a new instance of IOHandle.



8
9
10
11
12
13
# File 'lib/peruby/runtime/io_handle.rb', line 8

def initialize(io, layers: [])
  @io = io
  @lineno = 0
  @eof_flag = false
  @layers = layers
end

Instance Attribute Details

#eof_flagObject

Returns the value of attribute eof_flag.



6
7
8
# File 'lib/peruby/runtime/io_handle.rb', line 6

def eof_flag
  @eof_flag
end

#ioObject

Returns the value of attribute io.



6
7
8
# File 'lib/peruby/runtime/io_handle.rb', line 6

def io
  @io
end

#layersObject

Returns the value of attribute layers.



6
7
8
# File 'lib/peruby/runtime/io_handle.rb', line 6

def layers
  @layers
end

#linenoObject

Returns the value of attribute lineno.



6
7
8
# File 'lib/peruby/runtime/io_handle.rb', line 6

def lineno
  @lineno
end

Instance Method Details

#closeObject



30
31
32
33
34
35
# File 'lib/peruby/runtime/io_handle.rb', line 30

def close
  @io.close unless @io.closed?
  1
rescue IOError, SystemCallError
  ''
end

#read_record(separator) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/peruby/runtime/io_handle.rb', line 15

def read_record(separator)
  value = if separator.nil?
            @io.read
          elsif separator == ''
            @io.gets("\n\n")
          elsif separator.is_a?(Ref) && separator.target.is_a?(Scalar)
            @io.read(Conv.to_num(separator.target.get).to_i)
          else
            @io.gets(Conv.to_str(separator))
          end
  @eof_flag = value.nil?
  @lineno += 1 if value
  value
end