module Nebulous::Input::Parsing

Public Instance Methods

chunk() click to toggle source
# File lib/nebulous/input/parsing.rb, line 18
def chunk
  @chunk ||= Chunk.new chunk_options
end
chunk_options() click to toggle source
# File lib/nebulous/input/parsing.rb, line 54
def chunk_options
  Hash.new.tap do |attrs|
    attrs[:size] = options.chunk.to_i if options.chunk
  end
end
iterate(&block) click to toggle source
# File lib/nebulous/input/parsing.rb, line 37
def iterate(&block)
  while !file.eof?
    break if limit?
    chunk << replace_keys(parse_row)
    yield_chunk(chunk, &block) if block_given? && options.chunk
  end

  @chunk.to_a
end
limit?() click to toggle source
# File lib/nebulous/input/parsing.rb, line 26
def limit?
  options.limit && options.limit == @index
end
parse_row() click to toggle source
# File lib/nebulous/input/parsing.rb, line 4
def parse_row
  sequence
  Row.parse(read_complete_line, options).to_numeric.merge(@headers)
end
raw_headers() click to toggle source
# File lib/nebulous/input/parsing.rb, line 9
def raw_headers
  ln = read_complete_line
  Row.parse(ln, options)
end
read_headers() click to toggle source
# File lib/nebulous/input/parsing.rb, line 14
def read_headers
  @headers ||= Row.headers(read_complete_line, options)
end
replace_keys(row) click to toggle source
# File lib/nebulous/input/parsing.rb, line 47
def replace_keys(row)
  return row unless options.mapping
  row.map do |key, value|
    [options.mapping[key], value] if options.mapping.has_key?(key)
  end.compact.to_h
end
sequence() click to toggle source
# File lib/nebulous/input/parsing.rb, line 22
def sequence
  @index += 1
end
yield_chunk(chunk) { |chunk| ... } click to toggle source
# File lib/nebulous/input/parsing.rb, line 30
def yield_chunk(chunk, &_block)
  if chunk.full? || file.eof?
    yield chunk
    @chunk = nil
  end
end