Class: Uncsv
- Inherits:
-
Object
- Object
- Uncsv
- Includes:
- Enumerable
- Defined in:
- lib/uncsv.rb,
lib/uncsv/row.rb,
lib/uncsv/rows.rb,
lib/uncsv/config.rb,
lib/uncsv/header.rb,
lib/uncsv/version.rb,
lib/uncsv/key_normalizer.rb
Overview
Parses CSV data and iterates through it
Accepts a String, IO, or file, and outputs CSV rows. The rows can be
iterated over with each. Uncsv is also Enumerable, so all of those
built-in Ruby methods also work with it, including map, reduce, select,
etc.
Defined Under Namespace
Classes: Config, Header, KeyNormalizer, Row, Rows
Constant Summary collapse
- VERSION =
The current Uncsv library version
'1.1.0'
Class Method Summary collapse
-
.open(filename, opts = {}) {|config| ... } ⇒ Object
Create a new
Uncsvparser from a file. - .version ⇒ Object
Instance Method Summary collapse
-
#each {|row| ... } ⇒ Enumerator
Iterate over each data row of the CSV.
-
#header ⇒ Array
Get an array of the headers.
-
#initialize(data, opts = {}) {|config| ... } ⇒ Uncsv
constructor
Create a new
Uncsvparser.
Constructor Details
#initialize(data, opts = {}) {|config| ... } ⇒ Uncsv
Create a new Uncsv parser
28 29 30 31 32 33 34 35 36 |
# File 'lib/uncsv.rb', line 28 def initialize(data, opts = {}) @config = Config.new(opts) yield @config if block_given? @csv = if CSV.method(:new).arity == 2 CSV.new(data, @config.csv_opts) else CSV.new(data, **@config.csv_opts) end end |
Class Method Details
.open(filename, opts = {}) {|config| ... } ⇒ Object
Create a new Uncsv parser from a file
44 45 46 |
# File 'lib/uncsv.rb', line 44 def self.open(filename, opts = {}, &block) new(File.open(filename, 'rb'), opts, &block) end |
.version ⇒ Object
7 8 9 |
# File 'lib/uncsv/version.rb', line 7 def self.version Gem::Version.new(VERSION) end |
Instance Method Details
#each {|row| ... } ⇒ Enumerator
Iterate over each data row of the CSV
53 54 55 |
# File 'lib/uncsv.rb', line 53 def each(&block) rows.each(&block) end |
#header ⇒ Array
Get an array of the headers
Ordered from left to right
62 63 64 |
# File 'lib/uncsv.rb', line 62 def header rows.header end |