Skip to content

Commit

Permalink
Merge pull request #10 from culturecode/master
Browse files Browse the repository at this point in the history
Always return nil when named column isn't found.
  • Loading branch information
tatey committed Mar 4, 2015
2 parents 332a5bb + 9df2c1d commit f92825e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
8 changes: 6 additions & 2 deletions lib/conformist/column.rb
Expand Up @@ -18,11 +18,15 @@ def calculate_indices!(headers)
else
source
end
end.compact
end
end

def values_in enumerable
values = Array(enumerable).values_at(*indexes).map do |value|
enumerable = Array(enumerable)

values = Array(indexes).map do |index|
value = enumerable.at(index) if index

if value.respond_to? :strip
value.strip
else
Expand Down
9 changes: 9 additions & 0 deletions test/unit/integration_test.rb
Expand Up @@ -100,4 +100,13 @@ def test_named_columns
first = enumerable.to_a.first
assert_equal HashStruct.new(:name => 'Aaron', :age => '21', :gender => 'Male'), first
end

def test_missing_named_column
schema = Conformist.new do
column :state, 'State'
end
enumerable = schema.conform open_csv('citizens.csv'), :skip_first => true
first = enumerable.to_a.first
assert_equal HashStruct.new(:state => nil), first
end
end

0 comments on commit f92825e

Please sign in to comment.