-
Notifications
You must be signed in to change notification settings - Fork 0
Usage
hidenba edited this page Apr 14, 2012
·
7 revisions
[name,address,phone,email]というフォーマットのCSVの場合 CSVヘッダのカラムと同一名称でカラムを定義することができるようになる
require 'millionaire'
class Smaple
include Millionaire::Csv
column :name, presence: true, index:true
column :address, length: 100
column :phone
column :email
end
.loadメソッドにioオブジェクトを渡すことでCSVをロード
Sample.load(File.open file_path)
samples = Sample.all
samples.class.name => Array
sample = Sample.first
sample = Sample.last
sample = Sample.find 10
単一カラムを対象とした検索
samples = Sample.where(address: 'tokyo')
複数カラムを対象とした検索
samples = Sample.where(address: 'tokyo', name 'arice')
単一カラムで複数の値で検索
samples = Sample.where(address: ['tokyo','kyoto'])
column :name, pressence: true
column :name, length: 20
column :name, value: %w(aice bob chrice)
column :name, integer: true, value: 100..200
column :name, constraint: {format: {with: /\A[a-zA-Z]+\z/}}
column :name, uniq: true
column :name, index: true
index :name, [:name, :adress]