https://github.com/ksss/active_tsv
https://github.com/ksss/active_tsv
csv ruby tsv
Last synced: 6 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/ksss/active_tsv
- Owner: ksss
- License: mit
- Created: 2016-04-27T13:34:56.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2018-07-06T08:15:39.000Z (over 7 years ago)
- Last Synced: 2025-03-25T07:23:14.421Z (7 months ago)
- Topics: csv, ruby, tsv
- Language: Ruby
- Size: 109 KB
- Stars: 13
- Watchers: 3
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
README
# ActiveTsv
[](https://travis-ci.org/ksss/active_tsv)
A Class of Active record pattern for TSV/CSV
## Usage
data/users.tsv
```tsv
id name age
1 ksss 30
2 foo 29
3 bar 30
```data/nicknames.tsv
```tsv
id user_id nickname
1 1 yuki
2 1 kuri
3 1 k
4 2 f
``````ruby
require 'active_tsv'class User < ActiveTsv::Base
self.table_path = "data/users.tsv" # required
# self.encoding = Encoding::Shift_JIS # optional
# self.primary_key = "uid" # optional
has_many :nicknames
endclass Nickname < ActiveTsv::Base
self.table_path = "data/nicknames.tsv"
belongs_to :user
endUser.all
=> #, #, #]>
User.all.to_a
=> [#, #, #]User.first
#=> #
User.last
#=> #User.where(age: 30).each do |user|
user.name #=> "ksss", "bar"
endUser.where(age: 30).to_a
#=> [#, #]User.where(age: 30).last
#=> #User.where(age: 30).where(name: "ksss").first
#=> #User.where(id: [1, 2]).to_a
#=> [#, #]User.where.not(name: "ksss").first
#=> #User.group(:age).count
#=> {"30"=>2, "29"=>1}User.order(:name).to_a
#=> [#, #, #]User.order(name: :desc).to_a
=> [#, #, #]User.first.nicknames
#=> #, #, #]>Nickname.last.user
#=> #
```Also Supported **CSV**.
```ruby
require 'active_csv'
class User < ActiveCsv::Base
self.table_path = "data/users.csv"
end
```## Goal
Support all methods of ActiveRecord
## Installation
Add this line to your application's Gemfile:
```ruby
gem 'active_tsv'
```And then execute:
$ bundle
Or install it yourself as:
$ gem install active_tsv
## License
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).