Class: Nebulous::Parser
- Inherits:
-
Object
- Object
- Nebulous::Parser
- Includes:
- Input::Delimiters, Input::Parsing, Input::Reader
- Defined in:
- lib/nebulous/parser.rb
Constant Summary collapse
- DEFAULT_OPTIONS =
{ col_sep: nil, row_sep: nil, quote_char: '"', comment_exp: /^#/, chunk: false, headers: true, mapping: nil, limit: false, encoding: Encoding::UTF_8.to_s }
Instance Attribute Summary collapse
-
#file ⇒ Object
readonly
Returns the value of attribute file.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Instance Method Summary collapse
- #headers ⇒ Object
-
#initialize(file, *args) ⇒ Parser
constructor
A new instance of Parser.
- #process(&block) ⇒ Object
Methods included from Input::Delimiters
Methods included from Input::Parsing
#chunk, #chunk_options, #iterate, #limit?, #parse_row, #raw_headers, #read_headers, #replace_keys, #sequence, #yield_chunk
Methods included from Input::Reader
#encoding, #line_terminator, #read_complete_line, #read_input, #readline
Constructor Details
#initialize(file, *args) ⇒ Parser
Returns a new instance of Parser.
22 23 24 25 26 27 28 29 |
# File 'lib/nebulous/parser.rb', line 22 def initialize(file, *args) opts = args. @options = OpenStruct.new DEFAULT_OPTIONS.merge(opts) @file = read_input(file) merge_delimiters end |
Instance Attribute Details
#file ⇒ Object (readonly)
Returns the value of attribute file.
19 20 21 |
# File 'lib/nebulous/parser.rb', line 19 def file @file end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
20 21 22 |
# File 'lib/nebulous/parser.rb', line 20 def @options end |
Instance Method Details
#headers ⇒ Object
31 32 33 34 |
# File 'lib/nebulous/parser.rb', line 31 def headers @file.rewind raw_headers end |
#process(&block) ⇒ Object
36 37 38 39 40 41 42 43 |
# File 'lib/nebulous/parser.rb', line 36 def process(&block) @index = 0 read_headers if [:headers] iterate(&block) ensure reset file.rewind end |