Class: Localite::Backend::Tr::IO
- Inherits:
-
Object
- Object
- Localite::Backend::Tr::IO
- 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
-
#lineno ⇒ Object
readonly
Returns the value of attribute lineno.
Instance Method Summary collapse
- #eof? ⇒ Boolean
-
#initialize(src) ⇒ IO
constructor
A new instance of IO.
- #readline ⇒ Object
- #unreadline(line) ⇒ Object
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
#lineno ⇒ Object (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
17 18 19 |
# File 'lib/localite/tr.rb', line 17 def eof? @unreadline.nil? && @io.eof? end |
#readline ⇒ Object
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 |