Class: CsvReader::ParserFixed
- Inherits:
-
Object
- Object
- CsvReader::ParserFixed
- Defined in:
- lib/csvreader/parser_fixed.rb
Class Method Summary collapse
-
.build_logger ⇒ Object
add simple logger with debug flag/switch.
- .logger ⇒ Object
Instance Method Summary collapse
Class Method Details
.build_logger ⇒ Object
add simple logger with debug flag/switch
use Parser.debug = true # to turn on
todo/fix: use logutils instead of std logger - why? why not?
13 14 15 16 17 |
# File 'lib/csvreader/parser_fixed.rb', line 13 def self.build_logger() l = Logger.new( STDOUT ) l.level = :info ## set to :info on start; note: is 0 (debug) by default l end |
.logger ⇒ Object
18 |
# File 'lib/csvreader/parser_fixed.rb', line 18 def self.logger() @@logger ||= build_logger; end |
Instance Method Details
#logger ⇒ Object
19 |
# File 'lib/csvreader/parser_fixed.rb', line 19 def logger() self.class.logger; end |
#parse(data, width:, &block) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/csvreader/parser_fixed.rb', line 22 def parse( data, width:, &block ) ## note: input: required each_line (string or io/file for example) input = data ## assume it's a string or io/file handle if block_given? parse_lines( input, width: width, &block ) else records = [] parse_lines( input, width: width ) do |record| records << record end records end end |