Class: Csv::Configuration
- Inherits:
-
Object
- Object
- Csv::Configuration
- Defined in:
- lib/csvreader/reader.rb
Overview
STD_CSV_ENGINE = CSV ## to avoid name confusion use longer name - why? why not? find a better name? use __CSV__ or similar? or just ::CSV ??
Constant Summary collapse
- COMMENTS_REGEX =
lines starting with # (note: only leading spaces allowed)
/^\s*#/
- BLANK_REGEX =
skip all whitespace lines - note: use “” or , for a blank record!!!
/^\s*$/
- SKIP_REGEX =
Regexp.union( COMMENTS_REGEX, BLANK_REGEX )
Instance Attribute Summary collapse
-
#sep ⇒ Object
col_sep (column separator).
Instance Method Summary collapse
- #blank?(line) ⇒ Boolean
-
#default_options ⇒ Object
built-in (default) options todo: find a better name?.
-
#initialize ⇒ Configuration
constructor
A new instance of Configuration.
- #skip?(line) ⇒ Boolean
Constructor Details
#initialize ⇒ Configuration
Returns a new instance of Configuration.
27 28 29 30 31 32 33 |
# File 'lib/csvreader/reader.rb', line 27 def initialize @sep = ',' ## note: do NOT add headers as global - should ALWAYS be explicit ## headers (true/false) - changes resultset and requires different processing!!! self ## return self for chaining end |
Instance Attribute Details
#sep ⇒ Object
col_sep (column separator)
25 26 27 |
# File 'lib/csvreader/reader.rb', line 25 def sep @sep end |
Instance Method Details
#blank?(line) ⇒ Boolean
35 36 37 38 39 40 |
# File 'lib/csvreader/reader.rb', line 35 def blank?( line ) ## note: blank line does NOT include "blank" with spaces only!! ## use BLANK_REGEX in skip_lines to clean-up/skip/remove/ignore ## see skip_blanks in default_options line.empty? end |
#default_options ⇒ Object
built-in (default) options
todo: find a better name?
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/csvreader/reader.rb', line 55 def ## note: ## do NOT include sep character and ## do NOT include headers true/false here ## ## make default sep its own "global" default config ## e.g. Csv.config.sep = ## common options ## skip comments starting with # ## skip blank lines ## strip leading and trailing spaces ## NOTE/WARN: leading and trailing spaces NOT allowed/working with double quoted values!!!! defaults = { skip_blanks: true, ## note: skips lines with no whitespaces only!! (e.g. line with space is NOT blank!!) skip_lines: SKIP_REGEX, :converters => :strip } defaults end |
#skip?(line) ⇒ Boolean
47 48 49 50 51 |
# File 'lib/csvreader/reader.rb', line 47 def skip?( line ) ## check if comment line - skip comments ## see skip_lines in default_options line =~ SKIP_REGEX end |