module CsvRecord
Constants
- VERSION
Public Class Methods
build_class( headers )
click to toggle source
“magic” lazy auto-build schema from headers versions
# File lib/csvrecord/base.rb, line 84 def self.build_class( headers ) ## check: find a better name - why? why not? ## (auto-)build record class from an array of headers ## add fields (all types will be string for now) clazz = Class.new( Base ) headers.each do |header| ## downcase and remove all non-ascii chars etc. ## todo/fix: remove all non-ascii chars!!! ## todo: check if header starts with a number too!! name = header.downcase.gsub( ' ', '_' ) name = name.to_sym ## symbol-ify clazz.field( name ) end clazz end
define( &block )
click to toggle source
alternative class (record) builder
# File lib/csvrecord/base.rb, line 117 def self.define( &block ) ## check: rename super_class to base - why? why not? Record.define( Base, &block ) end
foreach( path, sep: nil, &block )
click to toggle source
# File lib/csvrecord/base.rb, line 106 def self.foreach( path, sep: nil, &block ) headers = CsvReader.header( path, sep: sep ) clazz = build_class( headers ) clazz.foreach( path, sep: sep, &block ) end
read( path, sep: nil )
click to toggle source
# File lib/csvrecord/base.rb, line 99 def self.read( path, sep: nil ) headers = CsvReader.header( path, sep: sep ) clazz = build_class( headers ) clazz.read( path, sep: sep ) end
root()
click to toggle source
# File lib/csvrecord/version.rb, line 24 def self.root File.expand_path( File.dirname(File.dirname(File.dirname(__FILE__))) ) end
version()
click to toggle source
# File lib/csvrecord/version.rb, line 16 def self.version VERSION end