Module: CsvHelper
- Included in:
- TmcHelpers
- Defined in:
- lib/helpers/tmc_helpers/csv_helper/csv_helper.rb
Instance Method Summary collapse
-
#csv_parse(data, args = {}) ⇒ Object
Public: Parses raw CSV data into a usable format.
-
#csv_read(data, options = {}) ⇒ Object
Public: Used to ingest CSV string into array of arrays data - String to be read options - You can set any reading preferences into the options hash Available options are: col_sep - The String placed between each field.
Instance Method Details
#csv_parse(data, args = {}) ⇒ Object
Public: Parses raw CSV data into a usable format.
data - String data to parse. header - Boolean indicating whether the data contains a header row (default: false).
Returns a Csv instance.
82 83 84 |
# File 'lib/helpers/tmc_helpers/csv_helper/csv_helper.rb', line 82 def csv_parse(data, args={}) Csv.parse(data, args) end |
#csv_read(data, options = {}) ⇒ Object
Public: Used to ingest CSV string into array of arrays data - String to be read options - You can set any reading preferences into the options hash Available options are: col_sep - The String placed between each field. This String will be transcoded into the data’s Encoding before parsing. row_sep - The String appended to the end of each row. This can be set to the special :auto setting, which requests that CSV automatically discover this from the data. quote_char - The character used to quote fields. This has to be a single character String. field_size_limit - This is a maximum size CSV will read ahead looking for the closing quote for a field. converters - An Array of names from the Converters Hash and/or lambdas that handle custom conversion. unconverted_fields - If set to true, an unconverted_fields() method will be added to all returned rows (Array or CSV::Row) that will return the fields as they were before conversion. Note that :headers supplied by Array or String were not fields of the document and thus will have an empty Array attached. headers - If set to :first_row or true, the initial row of the CSV string will be treated as a row of headers. If set to an Array, the contents will be used as the headers. If set to a String, the String is run through a call of ::parse_line with the same :col_sep, :row_sep, and :quote_char as this instance to produce an Array of headers. This setting causes #shift to return rows as CSV::Row objects instead of Arrays and #read to return CSV::Table objects instead of an Array of Arrays return_headers - When false, header rows are silently swallowed. If set to true, header rows are returned in a CSV::Row object with identical headers and fields (save that the fields do not go through the converters). write_headers - When true and :headers is set, a header row will be added to the output. header_converters - Identical in functionality to :converters save that the conversions are only made to header rows. skip_blanks - When set to a true value, CSV will skip over any rows with no content. force_quotes - When set to a true value, CSV will quote all CSV fields it creates. skip_lines - When set to an object responding to match, every line matching it is considered a comment and ignored during parsing. When set to a String, it is first converted to a Regexp. When set to nil no line is considered a comment. If the passed object does not respond to match, ArgumentError is thrown. Returns an array of arrays
72 73 74 |
# File 'lib/helpers/tmc_helpers/csv_helper/csv_helper.rb', line 72 def csv_read(data, ={}) CSV.parse(data, ) end |