Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add extra docs for CSV classes #102

Merged
merged 13 commits into from
Sep 13, 2019
16 changes: 16 additions & 0 deletions lib/csv/fields_converter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,22 @@
class CSV
class FieldsConverter
include Enumerable
#
# A CSV::FieldsConverter is a data structure for storing the
# fields converter properties to be passed as a parameter
# when parsing a new file (e.g. CSV::Parser.new(@io, parser_options))
#
# FieldsConverter options:
# 1. The option +converters+ stores all the converters added by you
# when calling the CSV::FieldsConverter.add_converter method.
# 2. The option +builtin_converters+ stores the following converter parsers:
# - :integer
# - :float
# - :date
# - :date_time
# - :numeric
# - :all
#

def initialize(options={})
@converters = []
Expand Down
10 changes: 10 additions & 0 deletions lib/csv/parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,16 @@

class CSV
class Parser
#
# A CSV::Parser is m17n aware. The parser works in the Encoding of the IO
# or String object being read from or written to. Your data is never transcoded
# (unless you ask Ruby to transcode it for you) and will literally be parsed in
# the Encoding it is in. Thus CSV will return Arrays or Rows of Strings in the
# Encoding of your data. This is accomplished by transcoding the parser itself
# into your Encoding.
#

# Raised when encoding is invalid
class InvalidEncoding < StandardError
end

Expand Down
10 changes: 10 additions & 0 deletions lib/csv/writer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@

class CSV
class Writer
#
# A CSV::Writer receives an output, prepares the header, format and output.
# It allows us to write new rows in the object and rewind it.
#
attr_reader :lineno
attr_reader :headers

Expand All @@ -22,6 +26,9 @@ def initialize(output, options)
@fields_converter = @options[:fields_converter]
end

#
# Adds a new row
#
def <<(row)
case row
when Row
Expand All @@ -47,6 +54,9 @@ def <<(row)
self
end

#
# Winds back to the beginning
#
def rewind
@lineno = 0
@headers = nil if @options[:headers].nil?
Expand Down