dbf 2.0.10 → 2.0.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,3 +1,3 @@
1
1
  module DBF
2
- VERSION = '2.0.10'
2
+ VERSION = '2.0.11'
3
3
  end
@@ -86,6 +86,22 @@ describe DBF::Column::Dbase do
86
86
  end
87
87
  end
88
88
 
89
+ context "with type B (binary)" do
90
+ context "with Foxpro dbf" do
91
+ it 'casts to float' do
92
+ column = DBF::Column::Dbase.new table, "ColumnName", "B", 1, 2
93
+ expect(column.type_cast("\xEC\x51\xB8\x1E\x85\x6B\x31\x40")).to be_a(Float)
94
+ expect(column.type_cast("\xEC\x51\xB8\x1E\x85\x6B\x31\x40")).to eq 17.42
95
+ end
96
+
97
+ it 'stores original precision' do
98
+ column = DBF::Column::Dbase.new table, "ColumnName", "B", 1, 0
99
+ expect(column.type_cast("\xEC\x51\xB8\x1E\x85\x6B\x31\x40")).to be_a(Float)
100
+ expect(column.type_cast("\xEC\x51\xB8\x1E\x85\x6B\x31\x40")).to eq 17.42
101
+ end
102
+ end
103
+ end
104
+
89
105
  context 'with type I (integer)' do
90
106
  context 'and 0 length' do
91
107
  it 'returns nil' do
@@ -236,18 +252,9 @@ describe DBF::Column::Dbase do
236
252
 
237
253
  context "with type B (binary)" do
238
254
  context "with Foxpro dbf" do
239
- context "when decimal is greater than 0" do
240
- it "outputs an float column" do
241
- column = DBF::Column::Dbase.new table, "ColumnName", "B", 1, 2
242
- expect(column.schema_definition).to eq "\"column_name\", :float\n"
243
- end
244
- end
245
-
246
- context "when decimal is 0" do
247
- it "outputs an integer column" do
248
- column = DBF::Column::Dbase.new table, "ColumnName", "B", 1, 0
249
- expect(column.schema_definition).to eq "\"column_name\", :integer\n"
250
- end
255
+ it "outputs a float column" do
256
+ column = DBF::Column::Dbase.new table, "ColumnName", "B", 1, 2
257
+ expect(column.schema_definition).to eq "\"column_name\", :float\n"
251
258
  end
252
259
  end
253
260
  end
@@ -1,4 +1,4 @@
1
- require "spec_helper"
1
+ require 'spec_helper'
2
2
 
3
3
  describe DBF::Table do
4
4
  let(:dbf_path) { fixture_path('dbase_83.dbf') }
@@ -18,7 +18,7 @@ describe DBF::Table do
18
18
 
19
19
  describe 'when given a path to a non-existent dbf file' do
20
20
  it 'raises a DBF::FileNotFound error' do
21
- expect { DBF::Table.new "x" }.to raise_error(DBF::FileNotFoundError, 'file not found: x')
21
+ expect { DBF::Table.new 'x' }.to raise_error(DBF::FileNotFoundError, 'file not found: x')
22
22
  end
23
23
  end
24
24
 
@@ -40,15 +40,15 @@ describe DBF::Table do
40
40
  end
41
41
  end
42
42
 
43
- context "#close" do
44
- it "closes the io" do
43
+ context '#close' do
44
+ it 'closes the io' do
45
45
  table.close
46
46
  expect { table.record(1) }.to raise_error(IOError)
47
47
  end
48
48
  end
49
49
 
50
- describe "#schema" do
51
- it "matches the test schema fixture" do
50
+ describe '#schema' do
51
+ it 'matches the test schema fixture' do
52
52
  control_schema = File.read(fixture_path('dbase_83_schema.txt'))
53
53
  expect(table.schema).to eq control_schema
54
54
  end
@@ -74,40 +74,40 @@ describe DBF::Table do
74
74
  describe 'when path param passed' do
75
75
  it 'creates a custom csv file' do
76
76
  table.to_csv('test.csv')
77
- expect(File.exists?('test.csv')).to be_truthy
77
+ expect(File.exist?('test.csv')).to be_truthy
78
78
  end
79
79
  end
80
80
  end
81
81
 
82
- describe "#record" do
83
- it "return nil for deleted records" do
82
+ describe '#record' do
83
+ it 'return nil for deleted records' do
84
84
  allow(table).to receive(:deleted_record?).and_return(true)
85
85
  expect(table.record(5)).to be_nil
86
86
  end
87
87
  end
88
88
 
89
- describe "#current_record" do
90
- it "should return nil for deleted records" do
89
+ describe '#current_record' do
90
+ it 'should return nil for deleted records' do
91
91
  allow(table).to receive(:deleted_record?).and_return(true)
92
92
  expect(table.record(0)).to be_nil
93
93
  end
94
94
  end
95
95
 
96
- describe "#find" do
97
- describe "with index" do
98
- it "returns the correct record" do
96
+ describe '#find' do
97
+ describe 'with index' do
98
+ it 'returns the correct record' do
99
99
  expect(table.find(5)).to eq table.record(5)
100
100
  end
101
101
  end
102
102
 
103
103
  describe 'with array of indexes' do
104
- it "returns the correct records" do
104
+ it 'returns the correct records' do
105
105
  expect(table.find([1, 5, 10])).to eq [table.record(1), table.record(5), table.record(10)]
106
106
  end
107
107
  end
108
108
 
109
- describe "with :all" do
110
- it "accepts a block" do
109
+ describe 'with :all' do
110
+ it 'accepts a block' do
111
111
  records = []
112
112
  table.find(:all, :weight => 0.0) do |record|
113
113
  records << record
@@ -115,53 +115,53 @@ describe DBF::Table do
115
115
  expect(records).to eq table.find(:all, :weight => 0.0)
116
116
  end
117
117
 
118
- it "returns all records if options are empty" do
118
+ it 'returns all records if options are empty' do
119
119
  expect(table.find(:all)).to eq table.to_a
120
120
  end
121
121
 
122
- it "returns matching records when used with options" do
123
- expect(table.find(:all, "WEIGHT" => 0.0)).to eq table.select {|r| r["weight"] == 0.0}
122
+ it 'returns matching records when used with options' do
123
+ expect(table.find(:all, 'WEIGHT' => 0.0)).to eq table.select {|r| r['weight'] == 0.0}
124
124
  end
125
125
 
126
- it "should AND multiple search terms" do
127
- expect(table.find(:all, "ID" => 30, :IMAGE => "graphics/00000001/TBC01.jpg")).to be_empty
126
+ it 'should AND multiple search terms' do
127
+ expect(table.find(:all, 'ID' => 30, :IMAGE => 'graphics/00000001/TBC01.jpg')).to be_empty
128
128
  end
129
129
 
130
- it "should match original column names" do
131
- expect(table.find(:all, "WEIGHT" => 0.0)).not_to be_empty
130
+ it 'should match original column names' do
131
+ expect(table.find(:all, 'WEIGHT' => 0.0)).not_to be_empty
132
132
  end
133
133
 
134
- it "matches symbolized column names" do
134
+ it 'matches symbolized column names' do
135
135
  expect(table.find(:all, :WEIGHT => 0.0)).not_to be_empty
136
136
  end
137
137
 
138
- it "matches downcased column names" do
139
- expect(table.find(:all, "weight" => 0.0)).not_to be_empty
138
+ it 'matches downcased column names' do
139
+ expect(table.find(:all, 'weight' => 0.0)).not_to be_empty
140
140
  end
141
141
 
142
- it "matches symbolized downcased column names" do
142
+ it 'matches symbolized downcased column names' do
143
143
  expect(table.find(:all, :weight => 0.0)).not_to be_empty
144
144
  end
145
145
  end
146
146
 
147
- describe "with :first" do
148
- it "returns the first record if options are empty" do
147
+ describe 'with :first' do
148
+ it 'returns the first record if options are empty' do
149
149
  expect(table.find(:first)).to eq table.record(0)
150
150
  end
151
151
 
152
- it "returns the first matching record when used with options" do
153
- expect(table.find(:first, "CODE" => "C")).to eq table.record(5)
152
+ it 'returns the first matching record when used with options' do
153
+ expect(table.find(:first, 'CODE' => 'C')).to eq table.record(5)
154
154
  end
155
155
 
156
- it "ANDs multiple search terms" do
157
- expect(table.find(:first, "ID" => 30, "IMAGE" => "graphics/00000001/TBC01.jpg")).to be_nil
156
+ it 'ANDs multiple search terms' do
157
+ expect(table.find(:first, 'ID' => 30, 'IMAGE' => 'graphics/00000001/TBC01.jpg')).to be_nil
158
158
  end
159
159
  end
160
160
  end
161
161
 
162
- describe "#filename" do
162
+ describe '#filename' do
163
163
  it 'returns the filename as a string' do
164
- expect(table.filename).to eq "dbase_83.dbf"
164
+ expect(table.filename).to eq 'dbase_83.dbf'
165
165
  end
166
166
  end
167
167
 
@@ -190,8 +190,9 @@ describe DBF::Table do
190
190
 
191
191
  describe '#column_names' do
192
192
  it 'is an array of all column names' do
193
- correct_column_names = ["ID", "CATCOUNT", "AGRPCOUNT", "PGRPCOUNT", "ORDER", "CODE", "NAME", "THUMBNAIL", "IMAGE", "PRICE", "COST", "DESC", "WEIGHT", "TAXABLE", "ACTIVE"]
193
+ correct_column_names = %w(ID CATCOUNT AGRPCOUNT PGRPCOUNT ORDER CODE NAME THUMBNAIL IMAGE PRICE COST DESC WEIGHT TAXABLE ACTIVE)
194
194
  expect(table.column_names).to eq correct_column_names
195
195
  end
196
196
  end
197
+
197
198
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dbf
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.10
4
+ version: 2.0.11
5
5
  platform: ruby
6
6
  authors:
7
7
  - Keith Morrison
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-06-20 00:00:00.000000000 Z
11
+ date: 2015-10-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: fastercsv