Sha256: 08ec3055d9e5920e1665b9ce69ac547337cdbd8ee85861f317202207b7b4f29e

Contents?: true

Size: 1.33 KB

Versions: 1

Compression:

Stored size: 1.33 KB

Contents

# SmartCSV

[![Gem Version](https://badge.fury.io/rb/smart_csv.png)](http://badge.fury.io/rb/smart_csv)

Extend CSV class.
This gem need header.

## FOR EXAMPLE

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

* Create a new record
```ruby
@data.create("id"=> '13', "lastname" => '1992')
```
* Select records
```ruby
@data.where('firstname' => 'One').where_not('id' => '4')
```
* Update record
```ruby
@data.where('firstname' => 'One').first.update({"lastname" => "Seven", "wartosc" => 2012}) }
```
* Delete all records
```ruby
@data.delete_all
```
* Delete all records from scope of condition
```ruby
@data.where('firstname' => 'One').delete_all
```
* Select all records which have 'id' attribute greater than 2
```ruby
@data.gt('id', '2')
```
* Select all records which have 'id' attribute greater or equal 2
```ruby
@data.ge('id', '2')
```
* Select all records which have 'id' attribute less than 2
```ruby
@data.lt('id', '2')
```
* Select all records which have 'id' attribute less or equal 2
```ruby
@data.le('id', '2')
```
* Select all records which have 'firstname' attribute equal 'Tom'
```ruby
@data.eq('firstname', 'Tom')
```
* Select all records which have 'firstname' attribute not equal 'Tom'
```ruby
@data.ne('firstname', 'Tom')
```

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
smart_csv-0.0.7 README.md