Class: Squiggle::ChunkParser

Inherits:
Object
  • Object
show all
Defined in:
lib/squiggle/chunk_parser.rb

Instance Method Summary collapse

Constructor Details

#initialize(chunk, options = {}) ⇒ ChunkParser

Returns a new instance of ChunkParser.



3
4
5
6
7
8
9
# File 'lib/squiggle/chunk_parser.rb', line 3

def initialize(chunk, options = {})
  options[:parser] = SquidStandardParser
  @parser = options[:parser].new(options[:time_zone])
  @lines = chunk.split("\n").select { |e| e.length > 5 }
  @current_line = next_line
  Rails.logger.info("Chunk Parser received: #{@lines.size} lines")
end

Instance Method Details

#current_lineObject



15
16
17
# File 'lib/squiggle/chunk_parser.rb', line 15

def current_line
  @current_line
end

#has_lines?Boolean

Returns:

  • (Boolean)


11
12
13
# File 'lib/squiggle/chunk_parser.rb', line 11

def has_lines?
  !@lines.empty?
end

#next_lineObject



19
20
21
22
23
24
25
26
27
28
# File 'lib/squiggle/chunk_parser.rb', line 19

def next_line
  return nil if @lines.empty?
  to_parse = @lines.shift
  logline = @parser.parse(to_parse)
  if logline.invalid?
    #STDERR.puts "Line is INVALID"
    logline = self.next_line # recurse
  end
  @current_line = logline
end