dbf 1.6.6 → 1.6.7

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1,6 @@
1
+ # 1.6.7
2
+ - memo columns return nil when no memo file found
3
+
1
4
  # 1.6.6
2
5
  - add binary data type support to ActiveRecord schema output
3
6
 
@@ -1,82 +1,28 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- dbf (1.6.5)
4
+ dbf (1.6.6)
5
5
  fastercsv (~> 1.5.4)
6
6
 
7
7
  GEM
8
8
  remote: http://rubygems.org/
9
9
  specs:
10
- Saikuro (1.1.0)
11
- activesupport (3.1.1)
12
- multi_json (~> 1.0)
13
10
  archive-tar-minitar (0.5.2)
14
- arrayfields (4.7.4)
15
- chronic (0.3.0)
16
- churn (0.0.13)
17
- chronic (>= 0.2.3)
18
- hirb
19
- json_pure
20
- main
21
- ruby_parser (~> 2.0.4)
22
- sexp_processor (~> 3.0.3)
23
- colored (1.2)
24
11
  columnize (0.3.4)
25
12
  diff-lcs (1.1.3)
26
- erubis (2.7.0)
27
13
  fastercsv (1.5.4)
28
- fattr (2.2.0)
29
- flay (1.4.3)
30
- ruby_parser (~> 2.0)
31
- sexp_processor (~> 3.0)
32
- flog (2.5.3)
33
- ruby_parser (~> 2.0)
34
- sexp_processor (~> 3.0)
35
- hirb (0.5.0)
36
- i18n (0.6.0)
37
- json_pure (1.6.1)
38
14
  linecache19 (0.5.12)
39
15
  ruby_core_source (>= 0.1.4)
40
- main (4.7.1)
41
- map (4.7.1)
42
- metric_fu (2.1.1)
43
- Saikuro (>= 1.1.0)
44
- activesupport (>= 2.0.0)
45
- chronic (~> 0.3.0)
46
- churn (>= 0.0.7)
47
- flay (>= 1.2.1)
48
- flog (>= 2.3.0)
49
- rails_best_practices (>= 0.6.4)
50
- rcov (>= 0.8.3.3)
51
- reek (>= 1.2.6)
52
- roodi (>= 2.1.0)
53
- syntax
54
- multi_json (1.0.3)
55
- progressbar (0.9.1)
56
- rails_best_practices (1.2.0)
57
- activesupport
58
- colored
59
- erubis
60
- i18n
61
- progressbar
62
- sexp_processor
63
- rake (0.9.2)
64
- rcov (0.9.11)
16
+ rake (0.9.2.2)
65
17
  rdoc (3.9.4)
66
- reek (1.2.8)
67
- ruby2ruby (~> 1.2)
68
- ruby_parser (~> 2.0)
69
- sexp_processor (~> 3.0)
70
- roodi (2.1.0)
71
- ruby_parser
72
- rspec (2.6.0)
73
- rspec-core (~> 2.6.0)
74
- rspec-expectations (~> 2.6.0)
75
- rspec-mocks (~> 2.6.0)
76
- rspec-core (2.6.4)
77
- rspec-expectations (2.6.0)
18
+ rspec (2.7.0)
19
+ rspec-core (~> 2.7.0)
20
+ rspec-expectations (~> 2.7.0)
21
+ rspec-mocks (~> 2.7.0)
22
+ rspec-core (2.7.1)
23
+ rspec-expectations (2.7.0)
78
24
  diff-lcs (~> 1.1.2)
79
- rspec-mocks (2.6.0)
25
+ rspec-mocks (2.7.0)
80
26
  ruby-debug-base19 (0.11.25)
81
27
  columnize (>= 0.3.1)
82
28
  linecache19 (>= 0.5.11)
@@ -85,26 +31,15 @@ GEM
85
31
  columnize (>= 0.3.1)
86
32
  linecache19 (>= 0.5.11)
87
33
  ruby-debug-base19 (>= 0.11.19)
88
- ruby2ruby (1.3.1)
89
- ruby_parser (~> 2.0)
90
- sexp_processor (~> 3.0)
91
34
  ruby_core_source (0.1.5)
92
35
  archive-tar-minitar (>= 0.5.2)
93
- ruby_parser (2.0.6)
94
- sexp_processor (~> 3.0)
95
- sexp_processor (3.0.7)
96
- syntax (1.0.0)
97
36
 
98
37
  PLATFORMS
99
38
  ruby
100
39
 
101
40
  DEPENDENCIES
102
- arrayfields
103
41
  dbf!
104
- fattr
105
- map
106
- metric_fu
107
42
  rake (~> 0.9.2)
108
43
  rdoc (~> 3.9.0)
109
- rspec (~> 2.6.0)
44
+ rspec (~> 2.7.0)
110
45
  ruby-debug19
data/Rakefile CHANGED
@@ -26,8 +26,8 @@ task :console do
26
26
  sh "irb -rubygems -I lib -r dbf.rb"
27
27
  end
28
28
 
29
- require 'metric_fu'
30
- MetricFu::Configuration.run do |config|
31
- config.rcov[:test_files] = ['spec/**/*_spec.rb']
32
- config.rcov[:rcov_opts] << "-Ispec"
33
- end
29
+ # require 'metric_fu'
30
+ # MetricFu::Configuration.run do |config|
31
+ # config.rcov[:test_files] = ['spec/**/*_spec.rb']
32
+ # config.rcov[:rcov_opts] << "-Ispec"
33
+ # end
@@ -101,7 +101,7 @@ module DBF
101
101
  when "M"
102
102
  ":text"
103
103
  when "B"
104
- if DBF::Table::FOXPRO_VERSIONS.include?(@version)
104
+ if DBF::Table::FOXPRO_VERSIONS.keys.include?(@version)
105
105
  decimal > 0 ? ":float" : ":integer"
106
106
  else
107
107
  ":text"
@@ -5,7 +5,9 @@ module DBF
5
5
  #
6
6
  # @param [DBF::Table] table
7
7
  def initialize(data, columns, version, memo)
8
- @data, @columns, @version, @memo = StringIO.new(data), columns, version, memo
8
+ @data = StringIO.new(data)
9
+ @columns, @version, @memo = columns, version, memo
10
+ @column_names = @columns.map {|column| column.underscored_name}
9
11
  define_accessors
10
12
  end
11
13
 
@@ -21,7 +23,7 @@ module DBF
21
23
  #
22
24
  # @return [Array]
23
25
  def to_a
24
- @columns.map { |column| attributes[Util.underscore(column.name)] }
26
+ @column_names.map { |name| attributes[name] }
25
27
  end
26
28
 
27
29
  # Do all search parameters match?
@@ -32,6 +34,7 @@ module DBF
32
34
  options.all? {|key, value| attributes[Util.underscore(key.to_s)] == value}
33
35
  end
34
36
 
37
+ # @return [Hash]
35
38
  def attributes
36
39
  return @attributes if @attributes
37
40
 
@@ -45,20 +48,22 @@ module DBF
45
48
  private
46
49
 
47
50
  def define_accessors #nodoc
48
- @columns.each do |column|
49
- name = column.underscored_name
50
- unless respond_to? name
51
- self.class.class_eval <<-END
52
- def #{name}
53
- @#{name} ||= attributes['#{name}']
54
- end
55
- END
56
- end
51
+ @column_names.each do |name|
52
+ next if respond_to? name
53
+ self.class.class_eval <<-END
54
+ def #{name}
55
+ @#{name} ||= attributes['#{name}']
56
+ end
57
+ END
57
58
  end
58
59
  end
59
60
 
60
61
  def init_attribute(column) #nodoc
61
- column.memo? ? @memo.get(get_memo_start_block(column)) : column.type_cast(unpack_data(column))
62
+ if column.memo?
63
+ @memo.get get_memo_start_block(column) if @memo
64
+ else
65
+ column.type_cast unpack_data(column)
66
+ end
62
67
  end
63
68
 
64
69
  def get_memo_start_block(column) #nodoc
@@ -7,7 +7,7 @@ module DBF
7
7
 
8
8
  DBF_HEADER_SIZE = 32
9
9
 
10
- VERSION_DESCRIPTIONS = {
10
+ VERSIONS = {
11
11
  "02" => "FoxBase",
12
12
  "03" => "dBase III without memo file",
13
13
  "04" => "dBase IV without memo file",
@@ -22,9 +22,7 @@ module DBF
22
22
  "fb" => "FoxPro without memo file"
23
23
  }
24
24
 
25
- FOXPRO_VERSIONS = VERSION_DESCRIPTIONS.map do |version, description|
26
- version if description =~ /FoxPro/
27
- end.compact
25
+ FOXPRO_VERSIONS = VERSIONS.select {|k,v| v =~ /FoxPro/}
28
26
 
29
27
  attr_reader :version # Internal dBase version number
30
28
  attr_reader :record_count # Total number of records
@@ -41,20 +39,20 @@ module DBF
41
39
  @memo = open_memo(path)
42
40
  end
43
41
 
42
+ # @return [TrueClass, FalseClass]
44
43
  def has_memo_file?
45
- @memo && memo_file_format
46
- end
47
-
48
- def memo_file_format
49
- @memo.format if has_memo_file?
44
+ !!@memo
50
45
  end
51
46
 
52
47
  # Closes the table and memo file
48
+ #
49
+ # @return [TrueClass, FalseClass]
53
50
  def close
54
51
  @memo && @memo.close
55
- @data.close
52
+ @data.close && @data.closed?
56
53
  end
57
54
 
55
+ # @return String
58
56
  def filename
59
57
  File.basename @data.path
60
58
  end
@@ -75,7 +73,9 @@ module DBF
75
73
  # @return [DBF::Record, NilClass]
76
74
  def record(index)
77
75
  seek(index * @record_length)
78
- deleted_record? ? nil : DBF::Record.new(@data.read(@record_length), columns, version, @memo)
76
+ if !deleted_record?
77
+ DBF::Record.new(@data.read(@record_length), columns, version, @memo)
78
+ end
79
79
  end
80
80
 
81
81
  alias_method :row, :record
@@ -84,7 +84,7 @@ module DBF
84
84
  #
85
85
  # @return [String]
86
86
  def version_description
87
- VERSION_DESCRIPTIONS[version]
87
+ VERSIONS[version]
88
88
  end
89
89
 
90
90
  # Generate an ActiveRecord::Schema
@@ -187,16 +187,22 @@ module DBF
187
187
 
188
188
  private
189
189
 
190
- def column_class
191
- @column_class ||= FOXPRO_VERSIONS.include?(version) ? FoxproColumn : Column
190
+ def column_class #nodoc
191
+ @column_class ||= if FOXPRO_VERSIONS.keys.include?(version)
192
+ FoxproColumn
193
+ else
194
+ Column
195
+ end
192
196
  end
193
197
 
194
- def column_count
198
+ def column_count #nodoc
195
199
  @column_count ||= (@header_length - DBF_HEADER_SIZE + 1) / DBF_HEADER_SIZE
196
200
  end
197
201
 
198
202
  def open_memo(path) #nodoc
199
- files = Dir.glob("#{File.dirname(path)}/#{File.basename(path, '.*')}*.{fpt,FPT,dbt,DBT}")
203
+ dirname = File.dirname(path)
204
+ basename = File.basename(path, '.*')
205
+ files = Dir.glob("#{dirname}/#{basename}*.{fpt,FPT,dbt,DBT}")
200
206
  files.any? ? Memo.open(files.first, version) : nil
201
207
  end
202
208
 
@@ -236,7 +242,7 @@ module DBF
236
242
  File.basename(@data.path, '.dbf') + '.csv'
237
243
  end
238
244
 
239
- def self.encodings
245
+ def self.encodings #nodoc
240
246
  @encodings ||= YAML.load_file File.expand_path("../encodings.yml", __FILE__)
241
247
  end
242
248
  end
@@ -1,5 +1,5 @@
1
1
  class Util
2
- def self.underscore(string)
2
+ def self.underscore(string) #nodoc
3
3
  string.gsub(/::/, '/').
4
4
  gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').
5
5
  gsub(/([a-z\d])([A-Z])/,'\1_\2').
@@ -1,3 +1,3 @@
1
1
  module DBF
2
- VERSION = '1.6.6'
2
+ VERSION = '1.6.7'
3
3
  end
@@ -1,9 +1,9 @@
1
1
  require "spec_helper"
2
2
 
3
3
  describe DBF::Table do
4
- # specify do
5
- # DBF::Table::FOXPRO_VERSIONS.should == %w(30 31 f5 fb)
6
- # end
4
+ specify 'foxpro versions' do
5
+ DBF::Table::FOXPRO_VERSIONS.keys.should == %w(30 31 f5 fb)
6
+ end
7
7
 
8
8
  context "when closed" do
9
9
  before do
@@ -23,16 +23,13 @@ describe DBF::Table do
23
23
  describe "#schema" do
24
24
  it "should match the test schema fixture" do
25
25
  table = DBF::Table.new "#{DB_PATH}/dbase_83.dbf"
26
- control_schema = File.read(File.dirname(__FILE__) + '/../fixtures/dbase_83_schema.txt')
27
-
26
+ control_schema = File.read("#{DB_PATH}/dbase_83_schema.txt")
28
27
  table.schema.should == control_schema
29
28
  end
30
29
  end
31
30
 
32
31
  describe '#to_csv' do
33
- before do
34
- @table = DBF::Table.new "#{DB_PATH}/dbase_83.dbf"
35
- end
32
+ let(:table) { DBF::Table.new "#{DB_PATH}/dbase_83.dbf" }
36
33
 
37
34
  after do
38
35
  FileUtils.rm_f 'dbase_83.csv'
@@ -40,13 +37,13 @@ describe DBF::Table do
40
37
  end
41
38
 
42
39
  it 'should create default dump.csv' do
43
- @table.to_csv
40
+ table.to_csv
44
41
  File.exists?('dbase_83.csv').should be_true
45
42
  end
46
43
 
47
44
  describe 'when path param passed' do
48
45
  it 'should create custom csv file' do
49
- @table.to_csv('test.csv')
46
+ table.to_csv('test.csv')
50
47
  File.exists?('test.csv').should be_true
51
48
  end
52
49
  end
@@ -165,5 +162,17 @@ describe DBF::Table do
165
162
  @table.filename.should == "dbase_03.dbf"
166
163
  end
167
164
  end
165
+
166
+ describe 'has_memo_file?' do
167
+ describe 'without a memo file' do
168
+ let(:table) { DBF::Table.new "#{DB_PATH}/dbase_03.dbf" }
169
+ specify { table.has_memo_file?.should be_false }
170
+ end
171
+
172
+ describe 'with a memo file' do
173
+ let(:table) { DBF::Table.new "#{DB_PATH}/dbase_30.dbf" }
174
+ specify { table.has_memo_file?.should be_true }
175
+ end
176
+ end
168
177
  end
169
178
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dbf
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.6.6
4
+ version: 1.6.7
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-10-30 00:00:00.000000000Z
12
+ date: 2011-11-23 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: fastercsv
16
- requirement: &70121607557520 !ruby/object:Gem::Requirement
16
+ requirement: &70198302238320 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
@@ -21,21 +21,21 @@ dependencies:
21
21
  version: 1.5.4
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70121607557520
24
+ version_requirements: *70198302238320
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: rspec
27
- requirement: &70121607556660 !ruby/object:Gem::Requirement
27
+ requirement: &70198302237860 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ~>
31
31
  - !ruby/object:Gem::Version
32
- version: 2.6.0
32
+ version: 2.7.0
33
33
  type: :development
34
34
  prerelease: false
35
- version_requirements: *70121607556660
35
+ version_requirements: *70198302237860
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: rake
38
- requirement: &70121607555460 !ruby/object:Gem::Requirement
38
+ requirement: &70198302237300 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ~>
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: 0.9.2
44
44
  type: :development
45
45
  prerelease: false
46
- version_requirements: *70121607555460
46
+ version_requirements: *70198302237300
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: rdoc
49
- requirement: &70121607554600 !ruby/object:Gem::Requirement
49
+ requirement: &70198302236780 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ~>
@@ -54,10 +54,10 @@ dependencies:
54
54
  version: 3.9.0
55
55
  type: :development
56
56
  prerelease: false
57
- version_requirements: *70121607554600
57
+ version_requirements: *70198302236780
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: ruby-debug19
60
- requirement: &70121607553520 !ruby/object:Gem::Requirement
60
+ requirement: &70198302236340 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - ! '>='
@@ -65,51 +65,7 @@ dependencies:
65
65
  version: '0'
66
66
  type: :development
67
67
  prerelease: false
68
- version_requirements: *70121607553520
69
- - !ruby/object:Gem::Dependency
70
- name: metric_fu
71
- requirement: &70121607552460 !ruby/object:Gem::Requirement
72
- none: false
73
- requirements:
74
- - - ! '>='
75
- - !ruby/object:Gem::Version
76
- version: '0'
77
- type: :development
78
- prerelease: false
79
- version_requirements: *70121607552460
80
- - !ruby/object:Gem::Dependency
81
- name: fattr
82
- requirement: &70121607551860 !ruby/object:Gem::Requirement
83
- none: false
84
- requirements:
85
- - - ! '>='
86
- - !ruby/object:Gem::Version
87
- version: '0'
88
- type: :development
89
- prerelease: false
90
- version_requirements: *70121607551860
91
- - !ruby/object:Gem::Dependency
92
- name: arrayfields
93
- requirement: &70121607551280 !ruby/object:Gem::Requirement
94
- none: false
95
- requirements:
96
- - - ! '>='
97
- - !ruby/object:Gem::Version
98
- version: '0'
99
- type: :development
100
- prerelease: false
101
- version_requirements: *70121607551280
102
- - !ruby/object:Gem::Dependency
103
- name: map
104
- requirement: &70121607550460 !ruby/object:Gem::Requirement
105
- none: false
106
- requirements:
107
- - - ! '>='
108
- - !ruby/object:Gem::Version
109
- version: '0'
110
- type: :development
111
- prerelease: false
112
- version_requirements: *70121607550460
68
+ version_requirements: *70198302236340
113
69
  description: A small fast library for reading dBase, xBase, Clipper and FoxPro database
114
70
  files.
115
71
  email: keithm@infused.org
@@ -143,8 +99,6 @@ files:
143
99
  - spec/dbf/file_formats_spec.rb
144
100
  - spec/dbf/record_spec.rb
145
101
  - spec/dbf/table_spec.rb
146
- - spec/fixtures/colores.DBF
147
- - spec/fixtures/colores.FPT
148
102
  - spec/fixtures/cp1251.dbf
149
103
  - spec/fixtures/dbase_03.dbf
150
104
  - spec/fixtures/dbase_30.dbf
Binary file
Binary file