Class: Localite::Backend::Tr::IO

Inherits:
Object
  • Object
show all
Defined in:
lib/localite/tr.rb

Overview

This class handles line reading from ios (files, etc.) and strings. It offers an one-line unread buffer.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(src) ⇒ IO

Returns a new instance of IO.



8
9
10
11
12
13
14
15
# File 'lib/localite/tr.rb', line 8

def initialize(src)
  @lineno = 0
  @io = if src.is_a?(String)
    StringIO.new(src)
  else
    src
  end
end

Instance Attribute Details

#linenoObject (readonly)

Returns the value of attribute lineno.



6
7
8
# File 'lib/localite/tr.rb', line 6

def lineno
  @lineno
end

Instance Method Details

#eof?Boolean

Returns:

  • (Boolean)


17
18
19
# File 'lib/localite/tr.rb', line 17

def eof?
  @unreadline.nil? && @io.eof?
end

#readlineObject



25
26
27
28
29
30
31
# File 'lib/localite/tr.rb', line 25

def readline
  r, @unreadline = @unreadline, nil
  r || begin
    @lineno += 1
    @io.readline
  end
end

#unreadline(line) ⇒ Object



21
22
23
# File 'lib/localite/tr.rb', line 21

def unreadline(line)
  @unreadline = line
end