Class: Nebulous::Parser
- Inherits:
-
Object
- Object
- Nebulous::Parser
- 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, remove_empty_values: true, 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
- #delimiters ⇒ Object
-
#initialize(file, *args) ⇒ Parser
constructor
A new instance of Parser.
- #process(&block) ⇒ Object
Constructor Details
#initialize(file, *args) ⇒ Parser
Returns a new instance of Parser.
19 20 21 22 23 24 25 26 |
# File 'lib/nebulous/parser.rb', line 19 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.
16 17 18 |
# File 'lib/nebulous/parser.rb', line 16 def file @file end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
17 18 19 |
# File 'lib/nebulous/parser.rb', line 17 def @options end |
Instance Method Details
#delimiters ⇒ Object
37 38 39 |
# File 'lib/nebulous/parser.rb', line 37 def delimiters @delimiters ||= DelimiterDetector.new(file.path).detect end |
#process(&block) ⇒ Object
28 29 30 31 32 33 34 35 |
# File 'lib/nebulous/parser.rb', line 28 def process(&block) @index = 0 read_headers iterate(&block) ensure reset file.rewind end |