dbf 1.6.1 → 1.6.2

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG.md CHANGED
@@ -1,3 +1,13 @@
1
+ ## 1.6.2
2
+ - add Table#filename method
3
+ - Rakefile now loads gems with bundler
4
+ - add Table#supports_encoding?
5
+ - simplify encodings.yml loader
6
+ - add rake and rdoc as development dependencies
7
+ - simplify open_memo file search logic
8
+ - remove unnecessary requires in spec helper
9
+ - fix cli summary
10
+
1
11
  ## 1.6.1
2
12
  - fix YAML issue when using MRI version > 1.9.1
3
13
  - remove Table#seek_to_index and Table#current_record private methods
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- dbf (1.6.0)
4
+ dbf (1.6.2)
5
5
  fastercsv (~> 1.5.4)
6
6
 
7
7
  GEM
@@ -13,6 +13,8 @@ GEM
13
13
  fastercsv (1.5.4)
14
14
  linecache19 (0.5.12)
15
15
  ruby_core_source (>= 0.1.4)
16
+ rake (0.9.2)
17
+ rdoc (3.9.4)
16
18
  rspec (2.6.0)
17
19
  rspec-core (~> 2.6.0)
18
20
  rspec-expectations (~> 2.6.0)
@@ -37,5 +39,7 @@ PLATFORMS
37
39
 
38
40
  DEPENDENCIES
39
41
  dbf!
42
+ rake (~> 0.9.2)
43
+ rdoc (~> 3.9.0)
40
44
  rspec (~> 2.6.0)
41
45
  ruby-debug19
data/Rakefile CHANGED
@@ -1,6 +1,8 @@
1
1
  # encoding: utf-8
2
2
 
3
3
  require 'rubygems'
4
+ require 'bundler/setup';
5
+ Bundler.setup(:default, :development)
4
6
 
5
7
  require 'rspec/core/rake_task'
6
8
  RSpec::Core::RakeTask.new :spec do |t|
@@ -1,61 +1,61 @@
1
1
  # inspired by http://trac.osgeo.org/gdal/ticket/2864
2
2
 
3
- "01": cp437 # U.S. MS–DOS
4
- "02": cp850 # International MS–DOS
5
- "03": cp1252 # Windows ANSI
6
- "08": cp865 # Danish OEM
7
- "09": cp437 # Dutch OEM
8
- "0a": cp850 # Dutch OEM*
9
- "0b": cp437 # Finnish OEM
10
- "0d": cp437 # French OEM
11
- "0e": cp850 # French OEM*
12
- "0f": cp437 # German OEM
13
- "10": cp850 # German OEM*
14
- "11": cp437 # Italian OEM
15
- "12": cp850 # Italian OEM*
16
- "13": cp932 # Japanese Shift-JIS
17
- "14": cp850 # Spanish OEM*
18
- "15": cp437 # Swedish OEM
19
- "16": cp850 # Swedish OEM*
20
- "17": cp865 # Norwegian OEM
21
- "18": cp437 # Spanish OEM
22
- "19": cp437 # English OEM (Britain)
23
- "1a": cp850 # English OEM (Britain)*
24
- "1b": cp437 # English OEM (U.S.)
25
- "1c": cp863 # French OEM (Canada)
26
- "1d": cp850 # French OEM*
27
- "1f": cp852 # Czech OEM
28
- "22": cp852 # Hungarian OEM
29
- "23": cp852 # Polish OEM
30
- "24": cp860 # Portuguese OEM
31
- "25": cp850 # Portuguese OEM*
32
- "26": cp866 # Russian OEM
33
- "37": cp850 # English OEM (U.S.)*
34
- "40": cp852 # Romanian OEM
35
- "4d": cp936 # Chinese GBK (PRC)
36
- "4e": cp949 # Korean (ANSI/OEM)
37
- "4f": cp950 # Chinese Big5 (Taiwan)
38
- "50": cp874 # Thai (ANSI/OEM)
39
- "57": cp1252 # ANSI
40
- "58": cp1252 # Western European ANSI
41
- "59": cp1252 # Spanish ANSI
42
- "64": cp852 # Eastern European MS–DOS
43
- "65": cp866 # Russian MS–DOS
44
- "66": cp865 # Nordic MS–DOS
45
- "67": cp861 # Icelandic MS–DOS
46
- "6a": cp737 # Greek MS–DOS (437G)
47
- "6b": cp857 # Turkish MS–DOS
48
- "6c": cp863 # French–Canadian MS–DOS
49
- "78": cp950 # Taiwan Big 5
50
- "79": cp949 # Hangul (Wansung)
51
- "7a": cp936 # PRC GBK
52
- "7b": cp932 # Japanese Shift-JIS
53
- "7c": cp874 # Thai Windows/MS–DOS
54
- "86": cp737 # Greek OEM
55
- "87": cp852 # Slovenian OEM
56
- "88": cp857 # Turkish OEM
57
- "c8": cp1250 # Eastern European Windows
58
- "c9": cp1251 # Russian Windows
59
- "ca": cp1254 # Turkish Windows
60
- "cb": cp1253 # Greek Windows
61
- "cc": cp1257 # Baltic Windows
3
+ "01": "cp437" # U.S. MS–DOS
4
+ "02": "cp850" # International MS–DOS
5
+ "03": "cp1252" # Windows ANSI
6
+ "08": "cp865" # Danish OEM
7
+ "09": "cp437" # Dutch OEM
8
+ "0a": "cp850" # Dutch OEM*
9
+ "0b": "cp437" # Finnish OEM
10
+ "0d": "cp437" # French OEM
11
+ "0e": "cp850" # French OEM*
12
+ "0f": "cp437" # German OEM
13
+ "10": "cp850" # German OEM*
14
+ "11": "cp437" # Italian OEM
15
+ "12": "cp850" # Italian OEM*
16
+ "13": "cp932" # Japanese Shift-JIS
17
+ "14": "cp850" # Spanish OEM*
18
+ "15": "cp437" # Swedish OEM
19
+ "16": "cp850" # Swedish OEM*
20
+ "17": "cp865" # Norwegian OEM
21
+ "18": "cp437" # Spanish OEM
22
+ "19": "cp437" # English OEM (Britain)
23
+ "1a": "cp850" # English OEM (Britain)*
24
+ "1b": "cp437" # English OEM (U.S.)
25
+ "1c": "cp863" # French OEM (Canada)
26
+ "1d": "cp850" # French OEM*
27
+ "1f": "cp852" # Czech OEM
28
+ "22": "cp852" # Hungarian OEM
29
+ "23": "cp852" # Polish OEM
30
+ "24": "cp860" # Portuguese OEM
31
+ "25": "cp850" # Portuguese OEM*
32
+ "26": "cp866" # Russian OEM
33
+ "37": "cp850" # English OEM (U.S.)*
34
+ "40": "cp852" # Romanian OEM
35
+ "4d": "cp936" # Chinese GBK (PRC)
36
+ "4e": "cp949" # Korean (ANSI/OEM)
37
+ "4f": "cp950" # Chinese Big5 (Taiwan)
38
+ "50": "cp874" # Thai (ANSI/OEM)
39
+ "57": "cp1252" # ANSI
40
+ "58": "cp1252" # Western European ANSI
41
+ "59": "cp1252" # Spanish ANSI
42
+ "64": "cp852" # Eastern European MS–DOS
43
+ "65": "cp866" # Russian MS–DOS
44
+ "66": "cp865" # Nordic MS–DOS
45
+ "67": "cp861" # Icelandic MS–DOS
46
+ "6a": "cp737" # Greek MS–DOS (437G)
47
+ "6b": "cp857" # Turkish MS–DOS
48
+ "6c": "cp863" # French–Canadian MS–DOS
49
+ "78": "cp950" # Taiwan Big 5
50
+ "79": "cp949" # Hangul (Wansung)
51
+ "7a": "cp936" # PRC GBK
52
+ "7b": "cp932" # Japanese Shift-JIS
53
+ "7c": "cp874" # Thai Windows/MS–DOS
54
+ "86": "cp737" # Greek OEM
55
+ "87": "cp852" # Slovenian OEM
56
+ "88": "cp857" # Turkish OEM
57
+ "c8": "cp1250" # Eastern European Windows
58
+ "c9": "cp1251" # Russian Windows
59
+ "ca": "cp1254" # Turkish Windows
60
+ "cb": "cp1253" # Greek Windows
61
+ "cc": "cp1257" # Baltic Windows
data/lib/dbf/memo.rb CHANGED
@@ -11,6 +11,10 @@ module DBF
11
11
  @data, @version = data, version
12
12
  end
13
13
 
14
+ def format
15
+ File.extname(@data.path)
16
+ end
17
+
14
18
  def get(start_block)
15
19
  if start_block > 0
16
20
  if format_fpt?
data/lib/dbf/table.rb CHANGED
@@ -36,12 +36,24 @@ module DBF
36
36
  get_header_info
37
37
  @memo = open_memo(path)
38
38
  end
39
+
40
+ def has_memo_file?
41
+ @memo && memo_file_format
42
+ end
43
+
44
+ def memo_file_format
45
+ @memo.format if has_memo_file?
46
+ end
39
47
 
40
48
  # Closes the table and memo file
41
49
  def close
42
50
  @memo && @memo.close
43
51
  @data.close
44
52
  end
53
+
54
+ def filename
55
+ File.basename @data.path
56
+ end
45
57
 
46
58
  # Calls block once for each record in the table. The record may be nil
47
59
  # if the record has been marked as deleted.
@@ -164,17 +176,16 @@ module DBF
164
176
  columns
165
177
  end
166
178
  end
179
+
180
+ def supports_encoding?
181
+ "".respond_to? :encoding
182
+ end
167
183
 
168
184
  private
169
185
 
170
186
  def open_memo(path) #nodoc
171
- %w(fpt FPT dbt DBT).each do |extname|
172
- filename = path.sub(/#{File.extname(path)[1..-1]}$/, extname)
173
- if File.exists?(filename)
174
- return Memo.open(filename, version)
175
- end
176
- end
177
- nil
187
+ files = Dir.glob("#{File.dirname(path)}/#{File.basename(path, '.*')}*.{fpt,FPT,dbt,DBT}")
188
+ files.any? ? Memo.open(files.first, version) : nil
178
189
  end
179
190
 
180
191
  def find_all(options) #nodoc
@@ -198,7 +209,7 @@ module DBF
198
209
  @data.rewind
199
210
  @version, @record_count, @header_length, @record_length, encoding_key =
200
211
  @data.read(DBF_HEADER_SIZE).unpack("H2 x3 V v2 x17H2")
201
- @encoding = self.class.encodings[encoding_key] if "".respond_to? :encoding
212
+ @encoding = self.class.encodings[encoding_key] if supports_encoding?
202
213
  end
203
214
 
204
215
  def seek(offset) #nodoc
@@ -214,7 +225,7 @@ module DBF
214
225
  end
215
226
 
216
227
  def self.encodings
217
- @encodings ||= YAML.load File.read(File.expand_path("../encodings.yml", __FILE__))
228
+ @encodings ||= YAML.load_file File.expand_path("../encodings.yml", __FILE__)
218
229
  end
219
230
  end
220
231
 
data/lib/dbf/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module DBF
2
- VERSION = '1.6.1'
2
+ VERSION = '1.6.2'
3
3
  end
@@ -47,7 +47,7 @@ describe DBF::Record do
47
47
 
48
48
  let(:record) { table.find(0) }
49
49
  it 'should automatically encodes to default system encoding' do
50
- if "".respond_to? :encoding
50
+ if table.supports_encoding?
51
51
  record.name.encoding.should == Encoding.default_external
52
52
  record.name.encode("UTF-8").unpack("H4").should == ["d0b0"] # russian a
53
53
  end
@@ -152,5 +152,14 @@ describe DBF::Table do
152
152
  end
153
153
  end
154
154
 
155
+ describe "filename" do
156
+ before do
157
+ @table = DBF::Table.new "#{DB_PATH}/dbase_03.dbf"
158
+ end
159
+
160
+ it 'should be dbase_03.dbf' do
161
+ @table.filename.should == "dbase_03.dbf"
162
+ end
163
+ end
155
164
  end
156
165
 
data/spec/spec_helper.rb CHANGED
@@ -1,8 +1,6 @@
1
1
  $:.unshift(File.dirname(__FILE__) + '/../lib/')
2
- require 'rubygems'
3
- require 'rspec'
4
2
  require 'dbf'
5
- require 'fileutils'
3
+ require 'rspec'
6
4
 
7
5
  DB_PATH = File.dirname(__FILE__) + '/fixtures' unless defined?(DB_PATH)
8
6
 
metadata CHANGED
@@ -1,79 +1,82 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: dbf
3
- version: !ruby/object:Gem::Version
4
- hash: 13
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.6.2
5
5
  prerelease:
6
- segments:
7
- - 1
8
- - 6
9
- - 1
10
- version: 1.6.1
11
6
  platform: ruby
12
- authors:
7
+ authors:
13
8
  - Keith Morrison
14
9
  autorequire:
15
10
  bindir: bin
16
11
  cert_chain: []
17
-
18
- date: 2011-09-28 00:00:00 Z
19
- dependencies:
20
- - !ruby/object:Gem::Dependency
12
+ date: 2011-10-16 00:00:00.000000000Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
21
15
  name: fastercsv
22
- prerelease: false
23
- requirement: &id001 !ruby/object:Gem::Requirement
16
+ requirement: &70325670387600 !ruby/object:Gem::Requirement
24
17
  none: false
25
- requirements:
18
+ requirements:
26
19
  - - ~>
27
- - !ruby/object:Gem::Version
28
- hash: 11
29
- segments:
30
- - 1
31
- - 5
32
- - 4
20
+ - !ruby/object:Gem::Version
33
21
  version: 1.5.4
34
22
  type: :runtime
35
- version_requirements: *id001
36
- - !ruby/object:Gem::Dependency
37
- name: rspec
38
23
  prerelease: false
39
- requirement: &id002 !ruby/object:Gem::Requirement
24
+ version_requirements: *70325670387600
25
+ - !ruby/object:Gem::Dependency
26
+ name: rspec
27
+ requirement: &70325670387140 !ruby/object:Gem::Requirement
40
28
  none: false
41
- requirements:
29
+ requirements:
42
30
  - - ~>
43
- - !ruby/object:Gem::Version
44
- hash: 23
45
- segments:
46
- - 2
47
- - 6
48
- - 0
31
+ - !ruby/object:Gem::Version
49
32
  version: 2.6.0
50
33
  type: :development
51
- version_requirements: *id002
52
- - !ruby/object:Gem::Dependency
53
- name: ruby-debug
54
34
  prerelease: false
55
- requirement: &id003 !ruby/object:Gem::Requirement
35
+ version_requirements: *70325670387140
36
+ - !ruby/object:Gem::Dependency
37
+ name: rake
38
+ requirement: &70325670386640 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ~>
42
+ - !ruby/object:Gem::Version
43
+ version: 0.9.2
44
+ type: :development
45
+ prerelease: false
46
+ version_requirements: *70325670386640
47
+ - !ruby/object:Gem::Dependency
48
+ name: rdoc
49
+ requirement: &70325670386180 !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: 3.9.0
55
+ type: :development
56
+ prerelease: false
57
+ version_requirements: *70325670386180
58
+ - !ruby/object:Gem::Dependency
59
+ name: ruby-debug19
60
+ requirement: &70325670385780 !ruby/object:Gem::Requirement
56
61
  none: false
57
- requirements:
58
- - - ">="
59
- - !ruby/object:Gem::Version
60
- hash: 3
61
- segments:
62
- - 0
63
- version: "0"
62
+ requirements:
63
+ - - ! '>='
64
+ - !ruby/object:Gem::Version
65
+ version: '0'
64
66
  type: :development
65
- version_requirements: *id003
66
- description: A small fast library for reading dBase, xBase, Clipper and FoxPro database files.
67
+ prerelease: false
68
+ version_requirements: *70325670385780
69
+ description: A small fast library for reading dBase, xBase, Clipper and FoxPro database
70
+ files.
67
71
  email: keithm@infused.org
68
- executables:
72
+ executables:
69
73
  - dbf
70
74
  extensions: []
71
-
72
- extra_rdoc_files:
75
+ extra_rdoc_files:
73
76
  - README.md
74
77
  - CHANGELOG.md
75
78
  - MIT-LICENSE
76
- files:
79
+ files:
77
80
  - CHANGELOG.md
78
81
  - Gemfile
79
82
  - Gemfile.lock
@@ -110,40 +113,30 @@ files:
110
113
  - spec/spec_helper.rb
111
114
  homepage: http://github.com/infused/dbf
112
115
  licenses: []
113
-
114
116
  post_install_message:
115
- rdoc_options:
117
+ rdoc_options:
116
118
  - --charset=UTF-8
117
- require_paths:
119
+ require_paths:
118
120
  - lib
119
- required_ruby_version: !ruby/object:Gem::Requirement
121
+ required_ruby_version: !ruby/object:Gem::Requirement
120
122
  none: false
121
- requirements:
122
- - - ">="
123
- - !ruby/object:Gem::Version
124
- hash: 3
125
- segments:
126
- - 0
127
- version: "0"
128
- required_rubygems_version: !ruby/object:Gem::Requirement
123
+ requirements:
124
+ - - ! '>='
125
+ - !ruby/object:Gem::Version
126
+ version: '0'
127
+ required_rubygems_version: !ruby/object:Gem::Requirement
129
128
  none: false
130
- requirements:
131
- - - ">="
132
- - !ruby/object:Gem::Version
133
- hash: 27
134
- segments:
135
- - 1
136
- - 3
137
- - 0
129
+ requirements:
130
+ - - ! '>='
131
+ - !ruby/object:Gem::Version
138
132
  version: 1.3.0
139
133
  requirements: []
140
-
141
134
  rubyforge_project:
142
135
  rubygems_version: 1.8.10
143
136
  signing_key:
144
137
  specification_version: 3
145
138
  summary: Read xBase files
146
- test_files:
139
+ test_files:
147
140
  - spec/dbf/column_spec.rb
148
141
  - spec/dbf/file_formats_spec.rb
149
142
  - spec/dbf/record_spec.rb