infused-dbf 1.0.7 → 1.0.8
Sign up to get free protection for your applications and to get access to all the features.
- data/README.txt +2 -2
- data/Rakefile +1 -1
- data/dbf.gemspec +4 -4
- data/lib/dbf/column.rb +10 -17
- data/spec/unit/column_spec.rb +12 -5
- metadata +3 -4
data/README.txt
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
DBF is a small fast library for reading dBase, xBase, Clipper and FoxPro database files
|
4
4
|
|
5
|
-
Copyright (c) 2006-
|
5
|
+
Copyright (c) 2006-2009 Keith Morrison <keithm@infused.org, www.infused.org>
|
6
6
|
|
7
7
|
* Official project page: http://rubyforge.org/projects/dbf
|
8
8
|
* API Documentation: http://dbf.rubyforge.org/docs
|
@@ -91,7 +91,7 @@ A small command-line utility called dbf is installed along with the gem.
|
|
91
91
|
|
92
92
|
(The MIT Licence)
|
93
93
|
|
94
|
-
Copyright (c) 2006-
|
94
|
+
Copyright (c) 2006-2009 Keith Morrison <keithm@infused.org, www.infused.org>
|
95
95
|
|
96
96
|
Permission is hereby granted, free of charge, to any person
|
97
97
|
obtaining a copy of this software and associated documentation
|
data/Rakefile
CHANGED
data/dbf.gemspec
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
s.name = %q{dbf}
|
3
|
-
s.version = "1.0.
|
3
|
+
s.version = "1.0.8"
|
4
4
|
|
5
5
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
6
6
|
s.authors = ["Keith Morrison"]
|
7
|
-
s.date = %q{2009-01-
|
7
|
+
s.date = %q{2009-01-02}
|
8
8
|
s.default_executable = %q{dbf}
|
9
|
-
s.description = %q{DBF is a small fast library for reading dBase, xBase, Clipper and FoxPro database files Copyright (c) 2006-
|
9
|
+
s.description = %q{DBF is a small fast library for reading dBase, xBase, Clipper and FoxPro database files Copyright (c) 2006-2009 Keith Morrison <keithm@infused.org, www.infused.org> * Official project page: http://rubyforge.org/projects/dbf * API Documentation: http://dbf.rubyforge.org/docs * To report bugs: http://www.rubyforge.org/tracker/?group_id=2009 * Questions: Email keithm@infused.org and put DBF somewhere in the subject line}
|
10
10
|
s.email = %q{keithm@infused.org}
|
11
11
|
s.executables = ["dbf"]
|
12
|
-
s.extra_rdoc_files = ["History.txt", "
|
12
|
+
s.extra_rdoc_files = ["History.txt", "README.txt"]
|
13
13
|
s.files = ["History.txt", "Manifest.txt", "README.txt", "Rakefile", "bin/dbf", "dbf.gemspec", "lib/dbf.rb", "lib/dbf/column.rb", "lib/dbf/globals.rb", "lib/dbf/record.rb", "lib/dbf/table.rb", "spec/fixtures/dbase_03.dbf", "spec/fixtures/dbase_30.dbf", "spec/fixtures/dbase_30.fpt", "spec/fixtures/dbase_83.dbf", "spec/fixtures/dbase_83.dbt", "spec/fixtures/dbase_83_schema.txt", "spec/fixtures/dbase_8b.dbf", "spec/fixtures/dbase_8b.dbt", "spec/fixtures/dbase_f5.dbf", "spec/fixtures/dbase_f5.fpt", "spec/functional/dbf_shared.rb", "spec/functional/format_03_spec.rb", "spec/functional/format_30_spec.rb", "spec/functional/format_83_spec.rb", "spec/functional/format_8b_spec.rb", "spec/functional/format_f5_spec.rb", "spec/spec_helper.rb", "spec/unit/column_spec.rb", "spec/unit/record_spec.rb", "spec/unit/table_spec.rb"]
|
14
14
|
s.has_rdoc = true
|
15
15
|
s.homepage = %q{http://github.com/infused/dm-dbf/tree/master}
|
data/lib/dbf/column.rb
CHANGED
@@ -6,8 +6,10 @@ module DBF
|
|
6
6
|
attr_reader :name, :type, :length, :decimal
|
7
7
|
|
8
8
|
def initialize(name, type, length, decimal)
|
9
|
-
raise ColumnLengthError, "field length must be greater than 0" unless length > 0
|
10
9
|
@name, @type, @length, @decimal = strip_non_ascii_chars(name), type, length, decimal
|
10
|
+
|
11
|
+
raise ColumnLengthError, "field length must be greater than 0" unless length > 0
|
12
|
+
raise ColumnNameError, "column name cannot be empty" if @name.length == 0
|
11
13
|
end
|
12
14
|
|
13
15
|
def type_cast(value)
|
@@ -31,10 +33,8 @@ module DBF
|
|
31
33
|
|
32
34
|
def decode_datetime(value)
|
33
35
|
days, milliseconds = value.unpack('l2')
|
34
|
-
|
35
|
-
|
36
|
-
seconds = ((milliseconds - (hours * MS_PER_HOUR) - (minutes * MS_PER_MINUTE)) / MS_PER_SECOND).to_i
|
37
|
-
DateTime.jd(days, hours, minutes, seconds)
|
36
|
+
seconds = milliseconds / 1000
|
37
|
+
DateTime.jd(days, seconds/3600, seconds/60 % 60, seconds % 60)
|
38
38
|
end
|
39
39
|
|
40
40
|
def unpack_integer(value)
|
@@ -66,19 +66,12 @@ module DBF
|
|
66
66
|
"\"#{name.underscore}\", #{data_type}\n"
|
67
67
|
end
|
68
68
|
|
69
|
-
|
70
|
-
|
69
|
+
# strip all non-ascii and non-printable characters
|
71
70
|
def strip_non_ascii_chars(s)
|
72
|
-
|
73
|
-
s.
|
74
|
-
|
75
|
-
|
76
|
-
else
|
77
|
-
raise ColumnNameError 'column name must not be empty' if clean.length == 0
|
78
|
-
return clean if char == 0
|
79
|
-
end
|
80
|
-
end
|
81
|
-
clean
|
71
|
+
# truncate the string at the first null character
|
72
|
+
s = s[0, s.index("\x00")] if s.index("\x00")
|
73
|
+
|
74
|
+
s.gsub(/[^\x20-\x7E]/,"")
|
82
75
|
end
|
83
76
|
end
|
84
77
|
|
data/spec/unit/column_spec.rb
CHANGED
@@ -24,8 +24,13 @@ describe DBF::Column do
|
|
24
24
|
end
|
25
25
|
|
26
26
|
it "should raise an error if length is greater than 0" do
|
27
|
-
lambda {
|
27
|
+
lambda { DBF::Column.new "ColumnName", "N", -1, 0 }.should raise_error(DBF::ColumnLengthError)
|
28
28
|
end
|
29
|
+
|
30
|
+
it "should raise error on emtpy column names" do
|
31
|
+
lambda { DBF::Column.new "\xFF\xFC", "N", 1, 0 }.should raise_error(DBF::ColumnNameError)
|
32
|
+
end
|
33
|
+
|
29
34
|
end
|
30
35
|
|
31
36
|
context "#type_cast" do
|
@@ -110,14 +115,16 @@ describe DBF::Column do
|
|
110
115
|
end
|
111
116
|
|
112
117
|
context "#strip_non_ascii_chars" do
|
118
|
+
before do
|
119
|
+
@column = DBF::Column.new "ColumnName", "N", 1, 0
|
120
|
+
end
|
121
|
+
|
113
122
|
it "should strip characters below decimal 32 and above decimal 127" do
|
114
|
-
column
|
115
|
-
column.send(:strip_non_ascii_chars, "--\x1F-\x68\x65\x6C\x6C\x6F world-\x80--").should == "---hello world---"
|
123
|
+
@column.strip_non_ascii_chars("--\x1F-\x68\x65\x6C\x6C\x6F world-\x80--").should == "---hello world---"
|
116
124
|
end
|
117
125
|
|
118
126
|
it "should truncate characters with decimal 0" do
|
119
|
-
column
|
120
|
-
column.send(:strip_non_ascii_chars, "--\x1F-\x68\x65\x6C\x6C\x6F \x00 world-\x80--").should == "---hello "
|
127
|
+
@column.strip_non_ascii_chars("--\x1F-\x68\x65\x6C\x6C\x6F \x00 world-\x80--").should == "---hello "
|
121
128
|
end
|
122
129
|
end
|
123
130
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: infused-dbf
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Keith Morrison
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-01-
|
12
|
+
date: 2009-01-02 00:00:00 -08:00
|
13
13
|
default_executable: dbf
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -30,7 +30,7 @@ dependencies:
|
|
30
30
|
- !ruby/object:Gem::Version
|
31
31
|
version: 1.8.2
|
32
32
|
version:
|
33
|
-
description: "DBF is a small fast library for reading dBase, xBase, Clipper and FoxPro database files Copyright (c) 2006-
|
33
|
+
description: "DBF is a small fast library for reading dBase, xBase, Clipper and FoxPro database files Copyright (c) 2006-2009 Keith Morrison <keithm@infused.org, www.infused.org> * Official project page: http://rubyforge.org/projects/dbf * API Documentation: http://dbf.rubyforge.org/docs * To report bugs: http://www.rubyforge.org/tracker/?group_id=2009 * Questions: Email keithm@infused.org and put DBF somewhere in the subject line"
|
34
34
|
email: keithm@infused.org
|
35
35
|
executables:
|
36
36
|
- dbf
|
@@ -38,7 +38,6 @@ extensions: []
|
|
38
38
|
|
39
39
|
extra_rdoc_files:
|
40
40
|
- History.txt
|
41
|
-
- Manifest.txt
|
42
41
|
- README.txt
|
43
42
|
files:
|
44
43
|
- History.txt
|