dbf 3.0.1 → 3.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5eb7b6698bb3117ab55add9db5b4b3cb768c82e8
4
- data.tar.gz: bfbc755dbd887584c102fdc249583c859c14011c
3
+ metadata.gz: 96a42e8a2472368295efedd4e47ea2a96bcced01
4
+ data.tar.gz: b5a4f4b6fcf91a0f100581293489b7e087d94b06
5
5
  SHA512:
6
- metadata.gz: 84b5da89c2953f28a559d47271614afeb452f0fbd3d770881634a4731f86279f327a67095b6191fed3e7916d886a498b880f4d69a002264b9a5fee8f62d32e09
7
- data.tar.gz: b67fa325a58fefd66b344bba83dc58718f4ecc07bdf5676e1f0ce2a698fce1907628069fb75a75d20ca6772988c6c21f1c242949f080786f3007f18d4762549b
6
+ metadata.gz: acaf78f1f98dc82f3feb05c2d70cda1bbdb64b6567de76a47723c2c440ddf00e16d54d358e12dac36139514b451487d1540e30b78ef510657d68554d97d08583
7
+ data.tar.gz: b6a86b0a5fb95da3e830847e7d39021b13fff15b06a81485db125b60ef6e99c29f34769e34fae0f1b9f4e809563047ae8667907bf3507a4268fa324c58f5150e
@@ -1,3 +1,10 @@
1
+ # 3.0.2
2
+ - Performance improvements for large files
3
+
4
+ # 3.0.1
5
+ - Support FoxPro (G) general field type
6
+ - Fix ruby warnings
7
+
1
8
  # 3.0.0
2
9
  - Requires Ruby version 2.0 and above
3
10
  - Support the (G) General Foxpro field type
@@ -1,14 +1,18 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- dbf (3.0.0)
4
+ dbf (3.0.1)
5
+ bindata
5
6
 
6
7
  GEM
7
8
  remote: https://rubygems.org/
8
9
  specs:
10
+ bindata (2.1.0)
11
+ byebug (8.2.0)
9
12
  coderay (1.1.0)
10
13
  diff-lcs (1.2.5)
11
14
  ffi (1.9.10)
15
+ ffi (1.9.10-java)
12
16
  formatador (0.2.5)
13
17
  guard (2.13.0)
14
18
  formatador (>= 0.2.4)
@@ -24,7 +28,7 @@ GEM
24
28
  guard (~> 2.1)
25
29
  guard-compat (~> 1.1)
26
30
  rspec (>= 2.99.0, < 4.0)
27
- listen (3.0.3)
31
+ listen (3.0.5)
28
32
  rb-fsevent (>= 0.9.3)
29
33
  rb-inotify (>= 0.9)
30
34
  lumberjack (1.0.9)
@@ -33,10 +37,15 @@ GEM
33
37
  notiffany (0.0.8)
34
38
  nenv (~> 0.1)
35
39
  shellany (~> 0.0)
36
- pry (0.10.2)
40
+ pry (0.10.3)
37
41
  coderay (~> 1.1.0)
38
42
  method_source (~> 0.8.1)
39
43
  slop (~> 3.4)
44
+ pry (0.10.3-java)
45
+ coderay (~> 1.1.0)
46
+ method_source (~> 0.8.1)
47
+ slop (~> 3.4)
48
+ spoon (~> 0.0)
40
49
  rb-fsevent (0.9.6)
41
50
  rb-inotify (0.9.5)
42
51
  ffi (>= 0.5.0)
@@ -55,12 +64,16 @@ GEM
55
64
  rspec-support (3.4.0)
56
65
  shellany (0.0.1)
57
66
  slop (3.6.0)
67
+ spoon (0.0.4)
68
+ ffi
58
69
  thor (0.19.1)
59
70
 
60
71
  PLATFORMS
72
+ java
61
73
  ruby
62
74
 
63
75
  DEPENDENCIES
76
+ byebug
64
77
  dbf!
65
78
  guard
66
79
  guard-rspec
data/README.md CHANGED
@@ -4,7 +4,6 @@
4
4
  [![Code Quality](http://img.shields.io/codeclimate/github/infused/dbf.svg?style=flat)](https://codeclimate.com/github/infused/dbf)
5
5
  [![Test Coverage](http://img.shields.io/codeclimate/coverage/github/infused/dbf.svg?style=flat)](https://codeclimate.com/github/infused/dbf)
6
6
  [![Dependency Status](http://img.shields.io/gemnasium/infused/dbf.svg?style=flat)](https://gemnasium.com/infused/dbf)
7
- [![Issues](https://img.shields.io/github/issues/infused/dbf.svg)](https://github.com/infused/dbf/issues)
8
7
  [![Total Downloads](https://img.shields.io/gem/dt/dbf.svg)](https://rubygems.org/gems/dbf/)
9
8
 
10
9
  DBF is a small fast library for reading dBase, xBase, Clipper and FoxPro
data/lib/dbf.rb CHANGED
@@ -5,8 +5,8 @@ require 'json'
5
5
 
6
6
  require 'dbf/schema'
7
7
  require 'dbf/record'
8
- require 'dbf/column'
9
8
  require 'dbf/column_type'
9
+ require 'dbf/column'
10
10
  require 'dbf/encodings'
11
11
  require 'dbf/header'
12
12
  require 'dbf/table'
@@ -8,6 +8,20 @@ module DBF
8
8
 
9
9
  attr_reader :table, :name, :type, :length, :decimal
10
10
 
11
+ TYPE_CAST_CLASS = {
12
+ N: ColumnType::Number,
13
+ I: ColumnType::SignedLong,
14
+ F: ColumnType::Float,
15
+ Y: ColumnType::Currency,
16
+ D: ColumnType::Date,
17
+ T: ColumnType::DateTime,
18
+ L: ColumnType::Boolean,
19
+ M: ColumnType::Memo,
20
+ B: ColumnType::Double,
21
+ G: ColumnType::General
22
+ }
23
+ TYPE_CAST_CLASS.default = ColumnType::String
24
+
11
25
  # Initialize a new DBF::Column
12
26
  #
13
27
  # @param [String] name
@@ -32,11 +46,7 @@ module DBF
32
46
  # @param [String] value
33
47
  # @return [Fixnum, Float, Date, DateTime, Boolean, String]
34
48
  def type_cast(value)
35
- return nil if length == 0
36
-
37
- klass = type_cast_class[type.to_sym]
38
- cast_value = klass.new(value, decimal).type_cast
39
- binary? ? cast_value : encode(cast_value)
49
+ type_cast_class.type_cast(value)
40
50
  end
41
51
 
42
52
  # Returns true if the column is a memo
@@ -46,13 +56,6 @@ module DBF
46
56
  @memo ||= type == 'M'
47
57
  end
48
58
 
49
- # Returns true if the column contains binary data
50
- #
51
- # @return [Boolean]
52
- def binary?
53
- @binary ||= type == 'G'
54
- end
55
-
56
59
  # Schema definition
57
60
  #
58
61
  # @return [String]
@@ -84,20 +87,13 @@ module DBF
84
87
 
85
88
  private
86
89
 
87
- # TODO this should be a constant
88
90
  def type_cast_class # nodoc
89
- h = Hash.new(ColumnType::String)
90
- h[:N] = ColumnType::Number
91
- h[:I] = ColumnType::SignedLong
92
- h[:F] = ColumnType::Float
93
- h[:Y] = ColumnType::Currency
94
- h[:D] = ColumnType::Date
95
- h[:T] = ColumnType::DateTime
96
- h[:L] = ColumnType::Boolean
97
- h[:M] = ColumnType::Memo
98
- h[:B] = ColumnType::Double
99
- h[:G] = ColumnType::General
100
- h
91
+ @type_cast_class ||=
92
+ if @length == 0
93
+ ColumnType::Nil
94
+ else
95
+ TYPE_CAST_CLASS[type.to_sym]
96
+ end.new(@decimal, @encoding)
101
97
  end
102
98
 
103
99
  def encode(value, strip_output = false) # nodoc
@@ -150,11 +146,11 @@ module DBF
150
146
  truncated_value.gsub(/[^\x20-\x7E]/, '')
151
147
  end
152
148
 
153
- def validate_length
149
+ def validate_length # nodoc
154
150
  raise LengthError, 'field length must be 0 or greater' if length < 0
155
151
  end
156
152
 
157
- def validate_name
153
+ def validate_name # nodoc
158
154
  raise NameError, 'column name cannot be empty' if @name.empty?
159
155
  end
160
156
  end
@@ -1,52 +1,63 @@
1
1
  module DBF
2
2
  module ColumnType
3
3
  class Base
4
- attr_reader :value, :decimal
4
+ ENCODING_ARGS = [
5
+ Encoding.default_external,
6
+ {undef: :replace, invalid: :replace}
7
+ ]
5
8
 
6
- def initialize(value, decimal)
7
- @value = value
9
+ attr_reader :decimal, :encoding
10
+
11
+ def initialize(decimal, encoding)
8
12
  @decimal = decimal
13
+ @encoding = encoding
14
+ end
15
+ end
16
+
17
+ class Nil < Base
18
+ def type_cast(value)
19
+ nil
9
20
  end
10
21
  end
11
22
 
12
23
  class Number < Base
13
- def type_cast
14
- decimal.zero? ? value.to_i : value.to_f
24
+ def type_cast(value)
25
+ @decimal.zero? ? value.to_i : value.to_f
15
26
  end
16
27
  end
17
28
 
18
29
  class Currency < Base
19
- def type_cast
30
+ def type_cast(value)
20
31
  (value.unpack('q<')[0] / 10_000.0).to_f
21
32
  end
22
33
  end
23
34
 
24
35
  class SignedLong < Base
25
- def type_cast
36
+ def type_cast(value)
26
37
  value.unpack('l<')[0]
27
38
  end
28
39
  end
29
40
 
30
41
  class Float < Base
31
- def type_cast
42
+ def type_cast(value)
32
43
  value.to_f
33
44
  end
34
45
  end
35
46
 
36
47
  class Double < Base
37
- def type_cast
48
+ def type_cast(value)
38
49
  value.unpack('E')[0]
39
50
  end
40
51
  end
41
52
 
42
53
  class Boolean < Base
43
- def type_cast
54
+ def type_cast(value)
44
55
  value.strip =~ /^(y|t)$/i ? true : false
45
56
  end
46
57
  end
47
58
 
48
59
  class Date < Base
49
- def type_cast
60
+ def type_cast(value)
50
61
  v = value.tr(' ', '0')
51
62
  v !~ /\S/ ? nil : ::Date.parse(v)
52
63
  rescue
@@ -55,7 +66,7 @@ module DBF
55
66
  end
56
67
 
57
68
  class DateTime < Base
58
- def type_cast
69
+ def type_cast(value)
59
70
  days, msecs = value.unpack('l2')
60
71
  secs = (msecs / 1000).to_i
61
72
  ::DateTime.jd(days, (secs / 3600).to_i, (secs / 60).to_i % 60, secs % 60)
@@ -65,21 +76,27 @@ module DBF
65
76
  end
66
77
 
67
78
  class Memo < Base
68
- def type_cast
69
- value
79
+ def type_cast(value)
80
+ if encoding and not value.nil?
81
+ value.force_encoding(@encoding).encode(*ENCODING_ARGS)
82
+ else
83
+ value
84
+ end
70
85
  end
71
86
  end
72
87
 
73
88
  class General < Base
74
- def type_cast
89
+ def type_cast(value)
75
90
  value
76
91
  end
77
92
  end
78
93
 
79
94
  class String < Base
80
- def type_cast
81
- value.strip
95
+ def type_cast(value)
96
+ value = value.strip
97
+ @encoding ? value.force_encoding(@encoding).encode(*ENCODING_ARGS) : value
82
98
  end
83
99
  end
100
+
84
101
  end
85
102
  end
@@ -90,7 +90,7 @@ module DBF
90
90
  end
91
91
 
92
92
  def init_attribute(column) # nodoc
93
- value = column.memo? ? memo(column) : unpack_data(column)
93
+ value = column.memo? ? memo(column) : get_data(column)
94
94
  column.type_cast(value)
95
95
  end
96
96
 
@@ -105,13 +105,15 @@ module DBF
105
105
  end
106
106
 
107
107
  def memo_start_block(column) # nodoc
108
- format = 'V' if %w(30 31).include?(@version)
109
- unpack_data(column, format).to_i
108
+ data = get_data(column)
109
+ if %w(30 31).include?(@version)
110
+ data = data.unpack('V').first
111
+ end
112
+ data.to_i
110
113
  end
111
114
 
112
- def unpack_data(column, format = nil) # nodoc
113
- format ||= "a#{column.length}"
114
- @data.read(column.length).unpack(format).first
115
+ def get_data(column) # nodoc
116
+ @data.read(column.length)
115
117
  end
116
118
  end
117
119
  end
@@ -1,3 +1,3 @@
1
1
  module DBF
2
- VERSION = '3.0.1'
2
+ VERSION = '3.0.2'
3
3
  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: 3.0.1
4
+ version: 3.0.2
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-11-20 00:00:00.000000000 Z
11
+ date: 2015-12-02 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: A small fast library for reading dBase, xBase, Clipper and FoxPro database
14
14
  files.