Class: Bparity::Corpus::Reader
- Inherits:
-
Object
- Object
- Bparity::Corpus::Reader
- Includes:
- Enumerable
- Defined in:
- lib/bparity/corpus.rb
Instance Method Summary collapse
- #each ⇒ Object
-
#initialize(path) ⇒ Reader
constructor
A new instance of Reader.
Constructor Details
#initialize(path) ⇒ Reader
Returns a new instance of Reader.
28 29 30 |
# File 'lib/bparity/corpus.rb', line 28 def initialize(path) @path = path end |
Instance Method Details
#each ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/bparity/corpus.rb', line 32 def each return enum_for(__method__) unless block_given? File.foreach(@path).with_index(1) do |line, number| yield JSON.parse(line) rescue JSON::ParserError => e raise Error, "Invalid JSONL at #{@path}:#{number}: #{e.}. Record the corpus again." end rescue Errno::ENOENT raise Error, "Cannot read corpus #{@path}. Run `bparity record` first." end |