Module: CsvRecord
- Defined in:
- lib/csvrecord/builder.rb,
lib/csvrecord/base.rb,
lib/csvrecord/version.rb
Overview
(record) builder mini language / domain-specific language (dsl)
Defined Under Namespace
Classes: Base, Builder, Field, Type
Constant Summary
collapse
- MAJOR =
todo: namespace inside version or something - why? why not??
0
- MINOR =
4
- PATCH =
0
- VERSION =
[MAJOR,MINOR,PATCH].join('.')
Class Method Summary
collapse
Class Method Details
.banner ⇒ Object
16
17
18
|
# File 'lib/csvrecord/version.rb', line 16
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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
|
# File 'lib/csvrecord/base.rb', line 106
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
|
# File 'lib/csvrecord/base.rb', line 81
def self.define( &block )
builder = Builder.new
if block.arity == 1
block.call( builder )
else
builder.instance_eval( &block )
end
builder.to_record
end
|
.foreach(path, sep: Csv.config.sep, &block) ⇒ Object
128
129
130
131
132
133
|
# File 'lib/csvrecord/base.rb', line 128
def self.foreach( path, sep: Csv.config.sep, &block )
= CsvReader.( path, sep: sep )
clazz = build_class( )
clazz.foreach( path, sep: sep, &block )
end
|
.read(path, sep: Csv.config.sep) ⇒ Object
121
122
123
124
125
126
|
# File 'lib/csvrecord/base.rb', line 121
def self.read( path, sep: Csv.config.sep )
= CsvReader.( path, sep: sep )
clazz = build_class( )
clazz.read( path, sep: sep )
end
|
.root ⇒ Object
20
21
22
|
# File 'lib/csvrecord/version.rb', line 20
def self.root
File.expand_path( File.dirname(File.dirname(File.dirname(__FILE__))) )
end
|
.version ⇒ Object
12
13
14
|
# File 'lib/csvrecord/version.rb', line 12
def self.version
VERSION
end
|