Skip to content

Commit

Permalink
add spec for currency columns
Browse files Browse the repository at this point in the history
  • Loading branch information
infused committed Mar 15, 2012
1 parent b25bd21 commit e962acc
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/dbf/column/base.rb
Expand Up @@ -28,7 +28,7 @@ def type_cast(value)
when 'N' then unpack_number(value) when 'N' then unpack_number(value)
when 'I' then unpack_unsigned_long(value) when 'I' then unpack_unsigned_long(value)
when 'F' then value.to_f when 'F' then value.to_f
when 'Y' then unpack_unsigned_long(value)/10000.0 when 'Y' then unpack_unsigned_long(value) / 10000.0
when 'D' then decode_date(value) when 'D' then decode_date(value)
when 'T' then decode_datetime(value) when 'T' then decode_datetime(value)
when 'L' then boolean(value) when 'L' then boolean(value)
Expand Down
8 changes: 8 additions & 0 deletions spec/dbf/column_spec.rb
Expand Up @@ -137,6 +137,14 @@
end end
end end


context 'with type Y (currency)' do
let(:column) { DBF::Column::Dbase.new "ColumnName", "Y", 8, 4, "31" }

it 'casts to float' do
column.type_cast(" \xBF\x02\x00\x00\x00\x00\x00").should == 18.0
end
end

context "#schema_definition" do context "#schema_definition" do
context 'with type N (number)' do context 'with type N (number)' do
it "outputs an integer column" do it "outputs an integer column" do
Expand Down

0 comments on commit e962acc

Please sign in to comment.