binaryparse 0.1.5 → 0.1.6
Sign up to get free protection for your applications and to get access to all the features.
- data/binaryparse.gemspec +1 -1
- data/examples/voter.rb +63 -0
- data/lib/blocker.rb +17 -0
- data/test/test_blocker.rb +13 -1
- metadata +3 -2
data/binaryparse.gemspec
CHANGED
data/examples/voter.rb
ADDED
@@ -0,0 +1,63 @@
|
|
1
|
+
require 'blocker'
|
2
|
+
|
3
|
+
class Voter < BinaryBlocker::Blocker
|
4
|
+
has_one :last_name, :sstring, :length => 35
|
5
|
+
has_one :first_name, :sstring, :length => 20
|
6
|
+
has_one :middle_name, :sstring, :length => 20
|
7
|
+
has_one :name_suffix, :sstring, :length => 3
|
8
|
+
# a post filter could convert this to an Fixnum
|
9
|
+
has_one :birthyear, :sstring, :length => 4
|
10
|
+
has_one :gender, :sstring, :length => 1
|
11
|
+
# a post filter could convert this to a date (but that is pretty slow)
|
12
|
+
has_one :registration, :sstring, :length => 8
|
13
|
+
has_one :addr_prefix, :sstring, :length => 1
|
14
|
+
has_one :addr_num, :sstring, :length => 7
|
15
|
+
has_one :addr_suffix, :sstring, :length => 4
|
16
|
+
has_one :addr_prefix_direction, :sstring, :length => 2
|
17
|
+
has_one :addr_street, :sstring, :length => 30
|
18
|
+
has_one :addr_street_type, :sstring, :length => 6
|
19
|
+
has_one :addr_suffix_direction, :sstring, :length => 2
|
20
|
+
has_one :addr_ext, :sstring, :length => 13
|
21
|
+
has_one :city, :sstring, :length => 35
|
22
|
+
has_one :state, :sstring, :length => 2
|
23
|
+
has_one :zip, :sstring, :length => 5
|
24
|
+
has_one :maddr1, :sstring, :length => 50
|
25
|
+
has_one :maddr2, :sstring, :length => 50
|
26
|
+
has_one :maddr3, :sstring, :length => 50
|
27
|
+
has_one :maddr4, :sstring, :length => 50
|
28
|
+
has_one :maddr5, :sstring, :length => 50
|
29
|
+
has_one :voter_id, :sstring, :length => 13
|
30
|
+
has_one :county_code, :sstring, :length => 2
|
31
|
+
has_one :jurisdiction, :sstring, :length => 5
|
32
|
+
has_one :ward, :sstring, :length => 6
|
33
|
+
has_one :school, :sstring, :length => 5
|
34
|
+
has_one :state_house, :sstring, :length => 5
|
35
|
+
has_one :state_senate, :sstring, :length => 5
|
36
|
+
has_one :congress, :sstring, :length => 5
|
37
|
+
has_one :country_commissioner, :sstring, :length => 5
|
38
|
+
has_one :village_code, :sstring, :length => 5
|
39
|
+
has_one :village_precinct, :sstring, :length => 6
|
40
|
+
has_one :school_precinct, :sstring, :length => 6
|
41
|
+
has_one :perm_absentee_ind, :sstring, :length => 1
|
42
|
+
has_one :status, :sstring, :length => 2
|
43
|
+
end
|
44
|
+
|
45
|
+
|
46
|
+
voter = Voter.new
|
47
|
+
voter.last_name = 'Hurley'
|
48
|
+
voter.first_name = 'Patrick'
|
49
|
+
voter.county_code = '82'
|
50
|
+
File.open("voter1.txt", "wb") do |vinfo|
|
51
|
+
vinfo.print voter.block
|
52
|
+
vinfo.print "Hurley Susan 82 "
|
53
|
+
end
|
54
|
+
|
55
|
+
File.open("voter1.txt") do |vinfo|
|
56
|
+
until vinfo.eof
|
57
|
+
voter = Voter.new(vinfo)
|
58
|
+
|
59
|
+
# You might want to do something more interesting here...
|
60
|
+
puts voter.last_name
|
61
|
+
puts voter.first_name
|
62
|
+
end
|
63
|
+
end
|
data/lib/blocker.rb
CHANGED
@@ -411,6 +411,23 @@ module BinaryBlocker
|
|
411
411
|
end
|
412
412
|
BinaryBlocker.register_klass(:string, FixedStringEncoder)
|
413
413
|
|
414
|
+
class SpacedStringEncoder < SimpleEncoder
|
415
|
+
def initialize(*opts)
|
416
|
+
@value = ''
|
417
|
+
initialize_options(*opts)
|
418
|
+
|
419
|
+
@length = @opts[:length].to_i
|
420
|
+
raise ArgumentError.new("Missing or invalid string length") unless @length > 0
|
421
|
+
@format = "A#{@length}"
|
422
|
+
|
423
|
+
@key = @opts[:key]
|
424
|
+
@valid = @opts[:valid]
|
425
|
+
|
426
|
+
initialize_data(*opts)
|
427
|
+
end
|
428
|
+
end
|
429
|
+
BinaryBlocker.register_klass(:sstring, SpacedStringEncoder)
|
430
|
+
|
414
431
|
class FixedUTF16StringEncoder < SimpleEncoder
|
415
432
|
def initialize(*opts)
|
416
433
|
initialize_options(*opts)
|
data/test/test_blocker.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
require 'blocker'
|
2
2
|
require 'stringio'
|
3
|
-
|
3
|
+
require 'test/unit' #unless defined? $ZENTEST and $ZENTEST
|
4
4
|
|
5
5
|
class TestBlocker < Test::Unit::TestCase
|
6
6
|
class BBTest1 < BinaryBlocker::Blocker
|
@@ -439,4 +439,16 @@ class TestBlocker < Test::Unit::TestCase
|
|
439
439
|
assert(t2)
|
440
440
|
assert_nil(t2.t)
|
441
441
|
end
|
442
|
+
|
443
|
+
class BBSpaceString < BinaryBlocker::Blocker
|
444
|
+
has_one :name, :sstring, :length => 10
|
445
|
+
has_one :last, :string, :length => 5
|
446
|
+
end
|
447
|
+
|
448
|
+
def test_space_string
|
449
|
+
buf = "Name Last "
|
450
|
+
ss = BBSpaceString.new(buf)
|
451
|
+
assert(ss)
|
452
|
+
assert_equal("Name", ss.name)
|
453
|
+
end
|
442
454
|
end
|
metadata
CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.9.0
|
|
3
3
|
specification_version: 1
|
4
4
|
name: binaryparse
|
5
5
|
version: !ruby/object:Gem::Version
|
6
|
-
version: 0.1.
|
7
|
-
date: 2006-09-
|
6
|
+
version: 0.1.6
|
7
|
+
date: 2006-09-14 00:00:00 -04:00
|
8
8
|
summary: Binaryparse is a simple Ruby DSL to parse semi-complicated binary structures. This includes structures dynamic in length, which cannot be handled by DL::Struct or BitStructEx.
|
9
9
|
require_paths:
|
10
10
|
- lib
|
@@ -35,6 +35,7 @@ files:
|
|
35
35
|
- test
|
36
36
|
- examples/cmasqls.rb
|
37
37
|
- examples/readme.txt
|
38
|
+
- examples/voter.rb
|
38
39
|
- lib/blocker.rb
|
39
40
|
- lib/buffered_io.rb
|
40
41
|
- test/test_blocker.rb
|