Class: Csv::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/csvreader/reader.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfiguration

Returns a new instance of Configuration.



44
45
46
47
48
49
50
51
52
53
# File 'lib/csvreader/reader.rb', line 44

def initialize
  @sep      = ','
  @blanks   = true
  @comments = true
  @trim     = true
  ## 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

#blanksObject

Returns the value of attribute blanks.



40
41
42
# File 'lib/csvreader/reader.rb', line 40

def blanks
  @blanks
end

#commentsObject

Returns the value of attribute comments.



41
42
43
# File 'lib/csvreader/reader.rb', line 41

def comments
  @comments
end

#dialectObject

Returns the value of attribute dialect.



42
43
44
# File 'lib/csvreader/reader.rb', line 42

def dialect
  @dialect
end

#naObject

not available (string or array of strings or nil) - rename to nas/nils/nulls - why? why not?



38
39
40
# File 'lib/csvreader/reader.rb', line 38

def na
  @na
end

#sepObject

col_sep (column separator)



37
38
39
# File 'lib/csvreader/reader.rb', line 37

def sep
  @sep
end

#trimObject

allow ltrim/rtrim/trim - why? why not?



39
40
41
# File 'lib/csvreader/reader.rb', line 39

def trim
  @trim
end

Instance Method Details

#blanks?Boolean

skip blank lines (with only 1+ spaces) note: for now blank lines with no spaces will always get skipped

Returns:

  • (Boolean)


60
# File 'lib/csvreader/reader.rb', line 60

def blanks?() @blanks; end

#comments?Boolean

Returns:

  • (Boolean)


63
# File 'lib/csvreader/reader.rb', line 63

def comments?() @comments; end

#default_optionsObject

built-in (default) options

todo: find a better name?


68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/csvreader/reader.rb', line 68

def default_options
  ## 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 = {
    blanks:   @blanks,    ## note: skips lines with no whitespaces only!! (e.g. line with space is NOT blank!!)

    comments: @comments,
    trim:     @trim
    ## :converters => :strip

  }
  defaults
end

#trim?Boolean

strip leading and trailing spaces

Returns:

  • (Boolean)


56
# File 'lib/csvreader/reader.rb', line 56

def trim?() @trim; end