Module: Nebulous::Input::Parsing
- Included in:
- Parser
- Defined in:
- lib/nebulous/input/parsing.rb
Instance Method Summary collapse
- #chunk ⇒ Object
- #chunk_options ⇒ Object
- #iterate(&block) ⇒ Object
- #limit? ⇒ Boolean
- #parse_row ⇒ Object
- #raw_headers ⇒ Object
- #read_headers ⇒ Object
- #replace_keys(row) ⇒ Object
- #sequence ⇒ Object
- #yield_chunk(chunk, &_block) ⇒ Object
Instance Method Details
#chunk ⇒ Object
17 18 19 |
# File 'lib/nebulous/input/parsing.rb', line 17 def chunk @chunk ||= Chunk.new end |
#chunk_options ⇒ Object
53 54 55 56 57 |
# File 'lib/nebulous/input/parsing.rb', line 53 def Hash.new.tap do |attrs| attrs[:size] = .chunk.to_i if .chunk end end |
#iterate(&block) ⇒ Object
36 37 38 39 40 41 42 43 44 |
# File 'lib/nebulous/input/parsing.rb', line 36 def iterate(&block) while !file.eof? break if limit? chunk << replace_keys(parse_row) yield_chunk(chunk, &block) if block_given? && .chunk end @chunk.to_a end |
#limit? ⇒ Boolean
25 26 27 |
# File 'lib/nebulous/input/parsing.rb', line 25 def limit? .limit && .limit == @index end |
#parse_row ⇒ Object
4 5 6 7 |
# File 'lib/nebulous/input/parsing.rb', line 4 def parse_row sequence Row.parse(read_complete_line, ).to_numeric.merge(@headers) end |
#raw_headers ⇒ Object
9 10 11 |
# File 'lib/nebulous/input/parsing.rb', line 9 def raw_headers Row.parse(readline, ) end |
#read_headers ⇒ Object
13 14 15 |
# File 'lib/nebulous/input/parsing.rb', line 13 def read_headers @headers ||= Row.headers(readline, ) if [:headers] end |
#replace_keys(row) ⇒ Object
46 47 48 49 50 51 |
# File 'lib/nebulous/input/parsing.rb', line 46 def replace_keys(row) return row unless .mapping row.map do |key, value| [.mapping[key], value] if .mapping.has_key?(key) end.compact.to_h end |
#sequence ⇒ Object
21 22 23 |
# File 'lib/nebulous/input/parsing.rb', line 21 def sequence @index += 1 end |
#yield_chunk(chunk, &_block) ⇒ Object
29 30 31 32 33 34 |
# File 'lib/nebulous/input/parsing.rb', line 29 def yield_chunk(chunk, &_block) if chunk.full? || file.eof? yield chunk @chunk = nil end end |