csv_processor

Version, currently master branch1 version
  • master branchlatestAug 15, 2018

github.com/drum445/csv_processor

CSV Processor in Crystal

3 stars
1 dependent
License: MIT

Installation

# Add this to your shard.yml
dependencies:
  csv_processor:
    github: drum445/csv_processor
    branch: master

master is a branch, not a release, so this tracks it rather than pinning a version.

Then run:

shards install

shard.yml

Crystal
0.24.2
License
MIT
Author
er

Dependencies

This version declares no dependencies.

README

csv_processor

Allows manipulation of CSV files based on the columns headerHeader == Column Name

Installation

Add this to your application's shard.yml:

dependencies:
  csv_processor:
    github: drum445/csv_processor

Usage

Using a file that looks like (test.csv):

name,age,gender
ed,23,m
bert,42,m
dave,55,m
Setup
require "csv_processor"

csv = CSVProcessor::CSVP.new("test.csv")
csv.read_file
Changing a value
# loop through our records and change the age
# of the record belonging to ed
csv.records.each do |row|
  if row["name"] == "ed"
    row["age"] = "35"
  end
end
Renaming a column header
csv.rename_column("age", "years")
Adding a column then setting the value
csv.add_column("job")

csv.records.each do |row|
  row["job"] = "developer"
end
Deleting a column
csv.delete_column("age")
Write to file
csv.write_file("processed_file.csv")

Contributing

  1. Fork it ( https://github.com/drum445/csv_processor/fork )
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create a new Pull Request

Contributors