palm 0.0.1 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/palm/pdb.rb +1 -0
- data/lib/palm/version.rb +1 -1
- data/lib/palm/waba_io.rb +2 -3
- data/lib/palm/waba_record.rb +18 -19
- data/test/waba_records_test.rb +34 -0
- metadata +2 -2
data/lib/palm/pdb.rb
CHANGED
data/lib/palm/version.rb
CHANGED
data/lib/palm/waba_io.rb
CHANGED
data/lib/palm/waba_record.rb
CHANGED
@@ -2,23 +2,22 @@ module Palm
|
|
2
2
|
WabaField = Struct.new(:name, :type)
|
3
3
|
|
4
4
|
class WabaRecord < Record
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
end
|
5
|
+
WRITE_TYPES = {
|
6
|
+
# Value || Default
|
7
|
+
:string=> lambda{|io,v| io.write_string(v||'' )},
|
8
|
+
:int=> lambda{|io,v| io.write_int( v||0 )},
|
9
|
+
:byte=> lambda{|io,v| io.write_byte( v||0 )},
|
10
|
+
:short=> lambda{|io,v| io.write_short( v||0 )},
|
11
|
+
:boolean=>lambda{|io,v| io.write_bool( v||false)},
|
12
|
+
}
|
13
|
+
|
14
|
+
READ_TYPES = {
|
15
|
+
:string=> lambda{|io| io.get_string },
|
16
|
+
:int=> lambda{|io| io.get_int },
|
17
|
+
:byte=> lambda{|io| io.get_byte },
|
18
|
+
:short=> lambda{|io| io.get_short },
|
19
|
+
:boolean=>lambda{|io| io.get_bool },
|
20
|
+
}
|
22
21
|
|
23
22
|
class << self
|
24
23
|
def field(name,type)
|
@@ -47,14 +46,14 @@ module Palm
|
|
47
46
|
# Assumes that the class_id has already been read off the stream
|
48
47
|
def read(waba_io)
|
49
48
|
self.class.fields.each do |f|
|
50
|
-
instance_variable_set "@#{f.name}",
|
49
|
+
instance_variable_set "@#{f.name}", READ_TYPES[f.type].call(waba_io)
|
51
50
|
end
|
52
51
|
self
|
53
52
|
end
|
54
53
|
|
55
54
|
def write(waba_io)
|
56
55
|
self.class.fields.each do |f|
|
57
|
-
|
56
|
+
WRITE_TYPES[f.type].call(waba_io, instance_variable_get("@#{f.name}"))
|
58
57
|
end
|
59
58
|
self
|
60
59
|
end
|
data/test/waba_records_test.rb
CHANGED
@@ -10,6 +10,15 @@ class TestWabaRecord < Palm::WabaRecord
|
|
10
10
|
end
|
11
11
|
end
|
12
12
|
|
13
|
+
class OveridesInitTestWabaRecord < Palm::WabaRecord
|
14
|
+
class_id 071
|
15
|
+
field :corridor, :string
|
16
|
+
field :site, :string
|
17
|
+
field :direction, :byte
|
18
|
+
def initialize
|
19
|
+
self.corridor = "I-5"
|
20
|
+
end
|
21
|
+
end
|
13
22
|
|
14
23
|
class TC_WabaRecords < Test::Unit::TestCase
|
15
24
|
def setup
|
@@ -60,6 +69,31 @@ class TC_WabaRecords < Test::Unit::TestCase
|
|
60
69
|
assert_equal "TEST SITE", @record.caps_site
|
61
70
|
end
|
62
71
|
|
72
|
+
# Regression test, +super+ is now not required in initialize
|
73
|
+
# Fixed v0.0.2
|
74
|
+
def test_custom_inits
|
75
|
+
assert_nothing_raised do
|
76
|
+
@record = OveridesInitTestWabaRecord.new
|
77
|
+
assert @record.corridor = "I-5"
|
78
|
+
io = Palm::WabaStringIO.new('', "w")
|
79
|
+
@record.write(io)
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
# Nil number values are implicitly written as 0, and strings as empty string
|
84
|
+
# Fixed v0.0.3
|
85
|
+
def test_writing_null_data
|
86
|
+
assert_nothing_raised do
|
87
|
+
assert_equal nil, @record.direction
|
88
|
+
io = Palm::WabaStringIO.new(s = '', "w")
|
89
|
+
@record.write(io)
|
90
|
+
assert s.length > 0 # ha! I had forgotten to write it out :)
|
91
|
+
@load_record = TestWabaRecord.new
|
92
|
+
@load_record.read(Palm::WabaStringIO.new(s, "r") )
|
93
|
+
assert_equal 0, @load_record.direction
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
63
97
|
def fill_record(record)
|
64
98
|
record.corridor = "I-5"
|
65
99
|
record.direction = 4
|
metadata
CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.8.11
|
|
3
3
|
specification_version: 1
|
4
4
|
name: palm
|
5
5
|
version: !ruby/object:Gem::Version
|
6
|
-
version: 0.0.
|
7
|
-
date: 2007-01-
|
6
|
+
version: 0.0.3
|
7
|
+
date: 2007-01-04 00:00:00 -08:00
|
8
8
|
summary: Pure Ruby library for reading and writing Palm PDB databases.
|
9
9
|
require_paths:
|
10
10
|
- lib
|