Project

smart_csv

0.0
No release in over 3 years
Low commit activity in last 3 years
Extend CSV class. CSV can delete or select some records.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

>= 2.0.0

Runtime

>= 1.0.0
>= 0
 Project Readme

SmartCSV

Gem Version Build Status Code Climate Dependency Status Coverage Status

Extend CSV class. CSV can delete or select some records.

Compatible with: Ruby 1.9.2, 1.9.3, and 2.0.0

Getting started

For Example we can use following data

data = "id,firstname,lastname\n1,One,One\n2,Two,Two\n4,One,Four\n5,One,Five"
csv = CSV.parse(data, {:col_sep => ',', :headers => true}

And now we can:

  • create a new record
csv.create("id"=> '13', "lastname" => '1992')
  • select records
csv.where('firstname' => 'One').where_not('id' => '4')
  • select opposite records
csv.not{where('firstname' => 'One')}
  • select records which satisfy two conditions
csv.where('firstname' => 'One').and{lt('id', 4)}
  • select records which satisfy one of two conditions
csv.where('firstname' => 'One').or{where('firstname' => 'Two')}
  • update record
csv.where('firstname' => 'One').first.update({"lastname" => "Seven", "wartosc" => 2012}) }
  • delete all records
csv.delete_all
  • delete all records from scope of condition
csv.where('firstname' => 'One').delete_all
  • select all records which have 'id' attribute greater than 2
csv.gt('id', '2')
  • select all records which have 'id' attribute greater or equal 2
csv.ge('id', '2')
  • select all records which have 'id' attribute less than 2
csv.lt('id', '2')
  • select all records which have 'id' attribute less or equal 2
csv.le('id', '2')
  • select all records which have 'firstname' attribute equal 'Tom'
csv.eq('firstname', 'Tom')
  • select all records which have 'firstname' attribute not equal 'Tom'
csv.ne('firstname', 'Tom')

License

SmartCSV uses the MIT license. Please check the LICENSE file for more details.