Class: Jcsv

Inherits:
Object
  • Object
show all
Defined in:
lib/jcsv.rb,
lib/locale.rb,
lib/reader.rb,
lib/filters.rb,
lib/dimensions.rb,
lib/map_reader.rb,
lib/constraints.rb,
lib/list_reader.rb,
lib/date_filters.rb,
lib/mdarray_reader.rb,
lib/numeric_filters.rb,
lib/supercsv_interface.rb

Overview

Copyright © 2015 Rodrigo Botafogo. All Rights Reserved. Permission to use, copy, modify, and distribute this software and its documentation, without fee and without a signed licensing agreement, is hereby granted, provided that the above copyright notice, this paragraph and the following two paragraphs appear in all copies, modifications, and distributions.

IN NO EVENT SHALL RODRIGO BOTAFOGO BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST PROFITS, ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF RODRIGO BOTAFOGO HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

RODRIGO BOTAFOGO SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE AND ACCOMPANYING DOCUMENTATION, IF ANY, PROVIDED HEREUNDER IS PROVIDED “AS IS”. RODRIGO BOTAFOGO HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.

Author:

  • Rodrigo Botafogo

Defined Under Namespace

Modules: Header, Headerless, NextFilter, Processors Classes: CLR, CMR, ConstraintViolation, DFSymbols, Dimension, Dimensions, DuplicateKeyError, Error, Filter, FilterError, ListReader, Locale, MDArrayReader, MapReader, Mapping, MissingHeadersError, RBCollector, RBConvertNilTo, RBDynamic, RBEquals, RBForbidSubstrings, RBGsub, RBIPAddr, RBInRange, RBIsElementOf, RBNotNil, RBOptional, RBParseBigDecimal, RBParseBignum, RBParseBool, RBParseChar, RBParseComplex, RBParseDate, RBParseDouble, RBParseFloat, RBParseHTTPDate, RBParseISO8601, RBParseInt, RBParseJD, RBParseJisx0301, RBParseLong, RBParseRFC2822, RBParseRFC3339, RBParseRFC822, RBParseRational, RBParseStrptime, RBParseXmlSchema, RBStrConstraints, RBStringGeneric, Reader

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#readerObject (readonly)

Returns the value of attribute reader.



63
64
65
# File 'lib/jcsv.rb', line 63

def reader
  @reader
end

Class Method Details

.ascii_only?Boolean

Returns:

  • (Boolean)


169
170
171
# File 'lib/constraints.rb', line 169

def self.ascii_only?
  RBStrConstraints.new(:ascii_only?)
end

.big_decimal(locale = Locale.default) ⇒ Object


Convert a String to a BigDecimal. It uses the String constructor of BigDecimal (new BigDecimal(“0.1”)) as it yields predictable results (see BigDecimal). If the data uses a character other than “.” as a decimal separator (Germany uses “,” for example), then use the constructor that accepts a DecimalFormatSymbols object, as it will convert the character to a “.” before creating the BigDecimal. Likewise if the data contains a grouping separator (Germany uses “.” for example) then supplying a DecimalFormatSymbols object will allow grouping separators to be removed before parsing.




221
222
223
# File 'lib/numeric_filters.rb', line 221

def self.big_decimal(locale = Locale.default)
  Jcsv::RBParseBigDecimal.new(locale)
end

.bignumObject



206
207
208
# File 'lib/numeric_filters.rb', line 206

def self.bignum
  RBParseBignum.new
end

.bool(true_values: ["true", "1", "y", "t"], false_values: ["false", "n", "0", "f"], ignore_case: true) ⇒ Object



282
283
284
285
286
# File 'lib/filters.rb', line 282

def self.bool(true_values: ["true", "1", "y", "t"],
              false_values: ["false", "n", "0", "f"],
              ignore_case: true)
  RBParseBool.new(true_values, false_values, ignore_case)
end

.charObject



296
297
298
# File 'lib/filters.rb', line 296

def self.char
  RBParseChar.new
end

.collectorObject



300
301
302
# File 'lib/filters.rb', line 300

def self.collector
  RBCollector.new
end

.complexObject



198
199
200
# File 'lib/numeric_filters.rb', line 198

def self.complex
  RBParseComplex.new
end

.convert_nil_to(value) ⇒ Object



288
289
290
# File 'lib/filters.rb', line 288

def self.convert_nil_to(value)
  RBConvertNilTo.new(value)
end

.date(start = Date::ITALY) ⇒ Object



228
229
230
# File 'lib/date_filters.rb', line 228

def self.date(start = Date::ITALY)
  Jcsv::RBParseDate.new(start)
end

.doubleObject



186
187
188
# File 'lib/numeric_filters.rb', line 186

def self.double
  RBParseDouble.new
end

.dynamic(*args, &block) ⇒ Object



308
309
310
# File 'lib/filters.rb', line 308

def self.dynamic(*args, &block)
  RBDynamic.new(*args, block: block)
end

.empty?Boolean

Returns:

  • (Boolean)


177
178
179
# File 'lib/constraints.rb', line 177

def self.empty?
  RBStrConstraints.new(:empty?)
end

.end_with?(*args) ⇒ Boolean

Returns:

  • (Boolean)


181
182
183
# File 'lib/constraints.rb', line 181

def self.end_with?(*args)
  RBStrConstraints.new(:end_with?, *args)
end

.equals(value = nil) ⇒ Object



165
166
167
# File 'lib/constraints.rb', line 165

def self.equals(value = nil)
  RBEquals.new(value)
end

.fixnumObject



190
191
192
# File 'lib/numeric_filters.rb', line 190

def self.fixnum
  RBParseBignum.new
end

.float(locale = Locale.default) ⇒ Object



194
195
196
# File 'lib/numeric_filters.rb', line 194

def self.float(locale = Locale.default)
  RBParseFloat.new(locale)
end

.forbid_substrings(substrings) ⇒ Object



197
198
199
# File 'lib/constraints.rb', line 197

def self.forbid_substrings(substrings)
  RBForbidSubstrings.new(substrings)
end

.gsub(*args, &block) ⇒ Object



312
313
314
# File 'lib/filters.rb', line 312

def self.gsub(*args, &block)
  RBGsub.new(*args, block: block)
end

.httpdate(start = Date::ITALY) ⇒ Object



212
213
214
# File 'lib/date_filters.rb', line 212

def self.httpdate(start = Date::ITALY)
  Jcsv::RBParseHTTPDate.new(start)
end

.in_range(min, max) ⇒ Object



161
162
163
# File 'lib/constraints.rb', line 161

def self.in_range(min, max)
  RBInRange.new(min, max)
end

.include?(*args) ⇒ Boolean

Returns:

  • (Boolean)


185
186
187
# File 'lib/constraints.rb', line 185

def self.include?(*args)
  RBStrConstraints.new(:include?, *args)
end

.intObject



178
179
180
# File 'lib/numeric_filters.rb', line 178

def self.int
  RBParseInt.new
end

.ipaddrObject



304
305
306
# File 'lib/filters.rb', line 304

def self.ipaddr
  RBIPAddr.new
end

.is_element_of(strings) ⇒ Object



201
202
203
# File 'lib/constraints.rb', line 201

def self.is_element_of(strings)
  RBIsElementOf.new(strings)
end

.iso8601(start = Date::ITALY) ⇒ Object



216
217
218
# File 'lib/date_filters.rb', line 216

def self.iso8601(start = Date::ITALY)
  Jcsv::RBParseISO8601.new(start)
end

.jdObject



220
221
222
# File 'lib/date_filters.rb', line 220

def self.jd
  Jcsv::RBParseJD.new
end

.jisx0301(start = Date::ITALY) ⇒ Object



224
225
226
# File 'lib/date_filters.rb', line 224

def self.jisx0301(start = Date::ITALY)
  Jcsv::RBParseJisx0301.new(start)
end

.longObject



182
183
184
# File 'lib/numeric_filters.rb', line 182

def self.long
  RBParseLong.new
end

.not_ascii?Boolean

Returns:

  • (Boolean)


173
174
175
# File 'lib/constraints.rb', line 173

def self.not_ascii?
  RBStrConstraints.new(:ascii_only?, check: false)
end

.not_nilObject



193
194
195
# File 'lib/constraints.rb', line 193

def self.not_nil
  RBNotNil.new
end

.optionalObject



292
293
294
# File 'lib/filters.rb', line 292

def self.optional
  RBOptional.new
end

.rationalObject



202
203
204
# File 'lib/numeric_filters.rb', line 202

def self.rational
  RBParseRational.new
end

.reader(*params) ⇒ Object





84
85
86
87
88
89
90
91
92
93
94
95
96
97
# File 'lib/jcsv.rb', line 84

def self.reader(*params)

  format = params[1]? params[1][:format] : :list
  
  case format
  when :map, :critbit
    @reader = Jcsv::MapReader.new(*params)
  when :mdarray
    @reader = Jcsv::MDArrayReader.new(*params)
  else
    @reader = Jcsv::ListReader.new(*params)
  end
  
end

.rfc2822(start = Date::ITALY) ⇒ Object



232
233
234
# File 'lib/date_filters.rb', line 232

def self.rfc2822(start = Date::ITALY)
  Jcsv::RBParseRFC2822.new(start)
end

.rfc3339(start = Date::ITALY) ⇒ Object



236
237
238
# File 'lib/date_filters.rb', line 236

def self.rfc3339(start = Date::ITALY)
  Jcsv::RBParseRFC3339.new(start)
end

.rfc822(start = Date::ITALY) ⇒ Object



240
241
242
# File 'lib/date_filters.rb', line 240

def self.rfc822(start = Date::ITALY)
  Jcsv::RBParseRFC822.new(start)
end

.start_with?(*args) ⇒ Boolean

Returns:

  • (Boolean)


189
190
191
# File 'lib/constraints.rb', line 189

def self.start_with?(*args)
  RBStrConstraints.new(:start_with?, *args)
end

.str(function, *args, &block) ⇒ Object



316
317
318
# File 'lib/filters.rb', line 316

def self.str(function, *args, &block)
  RBStringGeneric.new(function, *args, block: block)
end

.strptime(format, start = Date::ITALY) ⇒ Object



244
245
246
# File 'lib/date_filters.rb', line 244

def self.strptime(format, start = Date::ITALY)
  Jcsv::RBParseStrptime.new(format, start)
end

.writeObject


and Linux style line breaks are all supported when reading, so this preference won’t be used at all for reading). encoders below. quoteMode Allows you to enable surrounding quotes for writing (if a column wouldn’t normally be quoted because it doesn’t contain special characters).


Parameters:

  • end_of_line_symbols

    The end of line symbols to use when writing (Windows, Mac

  • encoder

    Use your own encoder when writing CSV. See the section on custom



76
77
78
# File 'lib/jcsv.rb', line 76

def self.write

end

.xmlschema(start = Date::ITALY) ⇒ Object



248
249
250
# File 'lib/date_filters.rb', line 248

def self.xmlschema(start = Date::ITALY)
  Jcsv::RBParseXmlSchema.new(start)
end

Instance Method Details

#filters=(filters) ⇒ Object





103
104
105
# File 'lib/jcsv.rb', line 103

def filters=(filters)
  @reader.filters=(filters)
end