Class: Kotoshu::Readers::StringReader

Inherits:
FileReader
  • Object
show all
Defined in:
lib/kotoshu/readers/file_reader.rb

Overview

String reader for reading from a string.

Useful for testing or when content is already in memory.

Constant Summary

Constants inherited from FileReader

FileReader::UTF8_BOM

Instance Attribute Summary

Attributes inherited from FileReader

#encoding, #line_no, #path

Instance Method Summary collapse

Methods inherited from FileReader

#close, #each, #has_next?, #next, #peek, #reset, #reset_encoding, #to_a

Constructor Details

#initialize(content, encoding = 'UTF-8') ⇒ StringReader

Create a new string reader.

Parameters:

  • content (String)

    The content to read

  • encoding (String) (defaults to: 'UTF-8')

    Encoding (default: ‘UTF-8’)



159
160
161
162
163
164
# File 'lib/kotoshu/readers/file_reader.rb', line 159

def initialize(content, encoding = 'UTF-8')
  @content = content
  @lines = content.split("\n", -1)
  @index = 0
  super(nil, encoding)
end