Class: CsvReader
- Inherits:
-
Object
show all
- Defined in:
- lib/csvreader/reader.rb,
lib/csvreader/buffer.rb,
lib/csvreader/parser.rb,
lib/csvreader/version.rb
Overview
note: uses a class for now - change to module - why? why not?
Defined Under Namespace
Classes: BufferIO, Parser
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
-
.banner ⇒ Object
-
.foreach(path, sep: Csv.config.sep, &block) ⇒ Object
-
.header(path, sep: Csv.config.sep) ⇒ Object
use header or headers - or use both (with alias)?.
-
.parse(txt, sep: Csv.config.sep) ⇒ Object
todo/fix: “unify” parse and parse_lines !!! check for block_given? - why? why not?.
-
.parse_line(txt, sep: Csv.config.sep, trim: Csv.config.trim?, na: Csv.config.na, dialect: Csv.config.dialect, converters: nil) ⇒ Object
-
.parse_lines(txt, sep: Csv.config.sep, &block) ⇒ Object
-
.read(path, sep: Csv.config.sep) ⇒ Object
-
.root ⇒ Object
-
.version ⇒ Object
Class Method Details
.banner ⇒ Object
16
17
18
|
# File 'lib/csvreader/version.rb', line 16
def self.banner
"csvreader/#{VERSION} on Ruby #{RUBY_VERSION} (#{RUBY_RELEASE_DATE}) [#{RUBY_PLATFORM}]"
end
|
.foreach(path, sep: Csv.config.sep, &block) ⇒ Object
156
157
158
159
160
161
162
|
# File 'lib/csvreader/reader.rb', line 156
def self.foreach( path, sep: Csv.config.sep, &block )
csv_options = Csv.config.default_options.merge(
col_sep: sep
)
Parser.foreach( path, &block ) end
|
use header or headers - or use both (with alias)?
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
|
# File 'lib/csvreader/reader.rb', line 165
def self.( path, sep: Csv.config.sep )
record = nil
File.open( path, 'r:bom|utf-8' ) do |file|
record = Parser.parse_line( file )
end
record end
|
.parse(txt, sep: Csv.config.sep) ⇒ Object
todo/fix: “unify” parse and parse_lines !!!
check for block_given? - why? why not?
131
132
133
134
135
136
137
|
# File 'lib/csvreader/reader.rb', line 131
def self.parse( txt, sep: Csv.config.sep )
csv_options = Csv.config.default_options.merge(
col_sep: sep
)
Parser.parse( txt ) end
|
.parse_line(txt, sep: Csv.config.sep, trim: Csv.config.trim?, na: Csv.config.na, dialect: Csv.config.dialect, converters: nil) ⇒ Object
113
114
115
116
117
118
119
120
121
122
123
124
|
# File 'lib/csvreader/reader.rb', line 113
def self.parse_line( txt, sep: Csv.config.sep,
trim: Csv.config.trim?,
na: Csv.config.na,
dialect: Csv.config.dialect,
converters: nil)
csv_options = Csv.config.default_options.merge(
col_sep: sep
)
Parser.parse_line( txt ) end
|
.parse_lines(txt, sep: Csv.config.sep, &block) ⇒ Object
139
140
141
142
143
144
145
|
# File 'lib/csvreader/reader.rb', line 139
def self.parse_lines( txt, sep: Csv.config.sep, &block )
csv_options = Csv.config.default_options.merge(
col_sep: sep
)
Parser.parse_lines( txt, &block ) end
|
.read(path, sep: Csv.config.sep) ⇒ Object
147
148
149
150
151
152
153
|
# File 'lib/csvreader/reader.rb', line 147
def self.read( path, sep: Csv.config.sep )
txt = File.open( path, 'r:bom|utf-8' ).read
parse( txt, sep: sep )
end
|
.root ⇒ Object
20
21
22
|
# File 'lib/csvreader/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/csvreader/version.rb', line 12
def self.version
VERSION
end
|