Module: CsvRecord
- Defined in:
- lib/csvrecord/base.rb,
lib/csvrecord/version.rb
Defined Under Namespace
Modules: Version
Classes: Base
Constant Summary
collapse
- VERSION =
[Version::MAJOR,
Version::MINOR,
Version::PATCH].join('.')
Class Method Summary
collapse
Class Method Details
.banner ⇒ Object
20
21
22
|
# File 'lib/csvrecord/version.rb', line 20
def self.banner
"csvrecord/#{VERSION} on Ruby #{RUBY_VERSION} (#{RUBY_RELEASE_DATE}) [#{RUBY_PLATFORM}]"
end
|
.build_class(headers) ⇒ Object
“magic” lazy auto-build schema from headers versions
84
85
86
87
88
89
90
91
92
93
94
95
96
97
|
# File 'lib/csvrecord/base.rb', line 84
def self.build_class( ) clazz = Class.new( Base )
.each do ||
name = .downcase.gsub( ' ', '_' )
name = name.to_sym clazz.field( name )
end
clazz
end
|
.define(&block) ⇒ Object
alternative class (record) builder
117
118
119
|
# File 'lib/csvrecord/base.rb', line 117
def self.define( &block ) Record.define( Base, &block )
end
|
.foreach(path, sep: nil, &block) ⇒ Object
106
107
108
109
110
111
|
# File 'lib/csvrecord/base.rb', line 106
def self.foreach( path, sep: nil, &block )
= CsvReader.( path, sep: sep )
clazz = build_class( )
clazz.foreach( path, sep: sep, &block )
end
|
.read(path, sep: nil) ⇒ Object
99
100
101
102
103
104
|
# File 'lib/csvrecord/base.rb', line 99
def self.read( path, sep: nil )
= CsvReader.( path, sep: sep )
clazz = build_class( )
clazz.read( path, sep: sep )
end
|
.root ⇒ Object
24
25
26
|
# File 'lib/csvrecord/version.rb', line 24
def self.root
File.expand_path( File.dirname(File.dirname(File.dirname(__FILE__))) )
end
|
.version ⇒ Object
16
17
18
|
# File 'lib/csvrecord/version.rb', line 16
def self.version
VERSION
end
|