Skip to content

Commit

Permalink
同一キーで複数の値を取得できるようにした
Browse files Browse the repository at this point in the history
  • Loading branch information
hidenba committed Feb 25, 2012
1 parent 979080b commit 591965f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 20 deletions.
9 changes: 6 additions & 3 deletions lib/millionaire/csv.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ def column(name, option={})
end
end
end
def columns; self.columns; end
def column_names; self.columns.map(&:name); end

def index(*name)
Expand All @@ -63,7 +62,6 @@ def indexing
self.indexes[k] = index_data
end
end
def indexes; self.indexes; end

def where(query)
if self.indexes.key? query.keys
Expand All @@ -72,7 +70,12 @@ def where(query)
group = self.csv_data.group_by do |r|
query.map{|k,v| r.send(k)}
end
group[query.values]

if query.values.all? {|val| val.is_a? Array }
query.values.map {|val| val.map {|v| group[Array.wrap(v)] } }.flatten
else
group[query.values]
end
end
end

Expand Down
23 changes: 6 additions & 17 deletions spec/millionaire/csv_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ class Column
subject { Column.new }
it { Column.column_names.each {|name| should respond_to name } }

it { Column.should have(7).columns }

context 'column validation' do
subject { Column.validators.index_by {|v| v.attributes.first } }
its([:presence]) { should be_kind_of ActiveModel::Validations::PresenceValidator }
Expand Down Expand Up @@ -121,23 +123,10 @@ class Where
end

describe 'operator' do
it 'lte' do
pending
end
it 'gte' do
pending
end
it 'lt' do
pending
end
it 'gt' do
pending
end
it 'eq' do
pending
end
it 'ne' do
pending
describe 'in' do
subject { Where.where(str_a: %w(1 3)) }
it { should have(2).record }
it { subject.map(&:line_no).should == [1,3] }
end
end
end
Expand Down

0 comments on commit 591965f

Please sign in to comment.