csv_processor

CSV Processor in Crystal

csv_processor

Allows manipulation of CSV files based on the columns header
Header == 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

Repository

csv_processor

Owner
Statistic
  • 3
  • 0
  • 0
  • 1
  • 0
  • over 6 years ago
  • April 26, 2018
License

MIT License

Links
Synced at

Fri, 22 Nov 2024 10:11:26 GMT

Languages