palm 0.0.1 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -70,6 +70,7 @@ module Palm
70
70
  @data = []
71
71
  @appinfo_block = nil
72
72
  @sort_block = nil
73
+ @backed_up_at = @created_at = @modified_at = Time.now
73
74
 
74
75
  case from
75
76
  when NilClass
@@ -2,7 +2,7 @@ module Palm #:nodoc:
2
2
  module VERSION #:nodoc:
3
3
  MAJOR = 0
4
4
  MINOR = 0
5
- TINY = 1
5
+ TINY = 3
6
6
 
7
7
  STRING = [MAJOR, MINOR, TINY].join('.')
8
8
  end
@@ -28,9 +28,8 @@ module Palm
28
28
  end
29
29
 
30
30
  def write_string(string)
31
- len = string.length
32
- write_short len
33
- self.write string
31
+ write_short(string.length)
32
+ write string
34
33
  end
35
34
 
36
35
  def write_short(short)
@@ -2,23 +2,22 @@ module Palm
2
2
  WabaField = Struct.new(:name, :type)
3
3
 
4
4
  class WabaRecord < Record
5
- def initialize
6
- @write_types = {
7
- :string=> lambda{|io,v| io.write_string v},
8
- :int=> lambda{|io,v| io.write_int v},
9
- :byte=> lambda{|io,v| io.write_byte v},
10
- :short=> lambda{|io,v| io.write_short v},
11
- :boolean=>lambda{|io,v| io.write_bool v},
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
- }
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}", @read_types[f.type].call(waba_io)
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
- @write_types[f.type].call(waba_io, instance_variable_get("@#{f.name}"))
56
+ WRITE_TYPES[f.type].call(waba_io, instance_variable_get("@#{f.name}"))
58
57
  end
59
58
  self
60
59
  end
@@ -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.1
7
- date: 2007-01-02 00:00:00 -08:00
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