class Threatinator::Parsers::Getline::Parser
Parses an IO, yielding each 'line' of data as deliniated by :separator. The text matching :separator will be included.
Attributes
separator[R]
Public Class Methods
new(opts = {})
click to toggle source
@param [Hash] opts @option opts [String] :separator (ānā) A character that will be used
to detect the end of a line.
Calls superclass method
Threatinator::Parser::new
# File lib/threatinator/parsers/getline/parser.rb, line 15 def initialize(opts = {}) @separator = opts.delete(:separator) || "\n" unless @separator.length == 1 raise ArgumentError.new(":separator must be exactly one character long") end super(opts) end
Public Instance Methods
==(other)
click to toggle source
Calls superclass method
Threatinator::Parser#==
# File lib/threatinator/parsers/getline/parser.rb, line 23 def ==(other) @separator == other.separator && super(other) end
run(io) { |record(str, line_number: lineno, pos_start: pos_start, pos_end: pos)| ... }
click to toggle source
@param [IO] io The IO to be parsed @yield [line] Gives one line to the block @yieldparam line [String] a line from the IO stream.
# File lib/threatinator/parsers/getline/parser.rb, line 31 def run(io) return enum_for(:each) unless block_given? lineno = 1 while str = io.gets(@separator) return if str.nil? pos_start = io.pos - str.length yield Record.new(str, line_number: lineno, pos_start: pos_start, pos_end: io.pos) lineno += 1 end nil end