iso8583 0.1.5 → 0.1.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- MWJiNGY0OGRlMDRjYjIzMzVkMjM0MTM0MjkwNjRmMDUyY2QyM2ZmYQ==
4
+ NjVlYWQ5YmQzY2ZlYWVjYWYxODliYTQ4NjViMzhiZDM3Y2NiY2I5Mw==
5
5
  data.tar.gz: !binary |-
6
- ZTVmMDk5YmExZjgzYTY3MTQzYmQ1MjQ4ZGI3MTJhNTVjMzE5NzZjMw==
7
- !binary "U0hBNTEy":
6
+ YzQ0OTBiYmI4MGQ0NjViMTI2YzNlM2NiZTUzNTIxZTliYWU4OTQzOQ==
7
+ SHA512:
8
8
  metadata.gz: !binary |-
9
- ZDE4OTM5MDcwMmE2NDA4MTdmMWJkMTljZWMwZWU0N2I1Yjc5MzIwY2ZmNjUz
10
- OGM1OTM4ZjYzNWY1YmM1MWQwYzcwYjdjOTAwZTgxYjk1YTlkNGE2MWRiOGM5
11
- OGU0ODJkYmFjNjA3N2UwOGE3ZDY2MWYxMmQzMTdjMWY5OTk2OTk=
9
+ NWU4Zjg3NDQwNjdmNThjOWYwZWYyOWEwZTQ5ZDU1ZDFkNWNlZDE5OWFiOTgw
10
+ NjY4M2QzNWIxNTlkNDAwM2Y5ZjUzZTM3ZTc3ZGNhMGQ3ODI4Zjg1OWVmOGMx
11
+ YmIzZWE4YWJlNDc5ZGIwNWJjMmMyZDBkZDE2M2EzMjdjNjU0OTg=
12
12
  data.tar.gz: !binary |-
13
- MDc0NGY5Y2EyNGY2YWQ5OThhNzNiZGJhZDliNzU1NzkxNTAxNDYwMDVmNDUz
14
- NDJjYjE1NjNlNDNiZDBkNjIyOWRlMTU3MjE1MjU0NzFmODlhNzRlZDI1YWVi
15
- Nzc0MGFiYzI4YmRjYjFhMzM2ZDg0YmJjNzE3NjA1MmVkYjgwMDc=
13
+ YzQ2YzU2N2E1YzM2YjRjZThiNTdiOWE2NGViYjA1NmMzNWQwZGNjZmJkMTg2
14
+ MDBlOWU2MTdmOTkyOWZkYmQwYWVmNjJkMTkxMDkyMTY3NDk1MjcyYjI3OWM2
15
+ MGU1MDVlN2QzNTAxNTAzZjQ4YzA0NmQ2ZmVmMzI0ZDlkMzYyZWQ=
data/CHANGELOG CHANGED
@@ -1,3 +1,18 @@
1
+ 0.1.6
2
+ =========
3
+ restrict to ruby < 2
4
+ allow removal of empty fields
5
+
6
+ 0.1.5
7
+ =========
8
+ MMDD Codec
9
+ BCD encoder checks odd length fields
10
+
11
+ 0.1.4
12
+ =========
13
+ Gemspec
14
+ reformatting
15
+
1
16
  0.1.3
2
17
  ==========
3
18
  bugfix, field definitions not duplicated
data/lib/iso8583.rb CHANGED
@@ -9,4 +9,5 @@ module ISO8583
9
9
  require "iso8583/bitmap"
10
10
  require "iso8583/message"
11
11
  require "iso8583/util"
12
+ require "iso8583/version"
12
13
  end
data/lib/iso8583/codec.rb CHANGED
@@ -58,6 +58,9 @@ module ISO8583
58
58
  # [+MMDDhhmmssCodec+] encodes Time, Datetime or String to the described date format, checking
59
59
  # that it is a valid date. Decodes to a DateTime instance, decoding and
60
60
  # encoding perform validity checks!
61
+ # [+MMDDCodec+] encodes Time, Datetime or String to the described date format, checking
62
+ # that it is a valid date. Decodes to a DateTime instance, decoding and
63
+ # encoding perform validity checks!
61
64
  # [+YYMMDDhhmmssCodec+] encodes Time, Datetime or String to the described date format, checking
62
65
  # that it is a valid date. Decodes to a DateTime instance, decoding and
63
66
  # encoding perform validity checks!
@@ -134,7 +137,7 @@ module ISO8583
134
137
 
135
138
  ANS_Codec = Codec.new
136
139
  ANS_Codec.encoder = lambda{|str|
137
- raise ISO8583Exception.new("Invalid value: #{str} must be [\x20-\x7E]") unless str =~ /^[\x20-\x7E]*$/
140
+ raise ISO8583Exception.new("Invalid value: #{str} must be [\\x20-\\x7E]") unless str =~ /^[\x20-\x7E]*$/
138
141
  str
139
142
  }
140
143
  ANS_Codec.decoder = PASS_THROUGH_DECODER
@@ -192,7 +195,9 @@ module ISO8583
192
195
  end
193
196
 
194
197
  MMDDhhmmssCodec = _date_codec("%m%d%H%M%S")
198
+ HhmmssCodec = _date_codec("%H%M%S")
195
199
  YYMMDDhhmmssCodec = _date_codec("%y%m%d%H%M%S")
196
200
  YYMMCodec = _date_codec("%y%m")
201
+ MMDDCodec = _date_codec("%m%d")
197
202
 
198
203
  end
data/lib/iso8583/field.rb CHANGED
@@ -52,7 +52,11 @@ module ISO8583
52
52
  # special treatment, you may need to override this method alltogether.
53
53
  # In other cases, the padding has to be implemented by the codec, such as BCD with an odd number of nibbles.
54
54
  def encode(value)
55
- encoded_value = codec.encode(value)
55
+ begin
56
+ encoded_value = codec.encode(value)
57
+ rescue ISO8583Exception
58
+ raise ISO8583Exception.new($!.message+" (#{name})")
59
+ end
56
60
 
57
61
  if padding
58
62
  if padding.arity == 1
@@ -33,8 +33,10 @@ module ISO8583
33
33
  # [+ANS+] fixed length ASCII [\x20-\x7E], padding left, spaces
34
34
  # [+B+] binary data, padding left using nulls (0x00)
35
35
  # [+MMDDhhmmss+] Date, formatted as described in ASCII numerals
36
+ # [+MMDD+] Date, formatted as described in ASCII numerals
36
37
  # [+YYMMDDhhmmss+] Date, formatted as named in ASCII numerals
37
38
  # [+YYMM+] Expiration Date, formatted as named in ASCII numerals
39
+ # [+Hhmmss+] Date, formatted in ASCII hhmmss
38
40
 
39
41
 
40
42
  # Special form to de/encode variable length indicators, two bytes ASCII numerals
@@ -161,5 +163,13 @@ module ISO8583
161
163
  YYMM = Field.new
162
164
  YYMM.codec = YYMMCodec
163
165
  YYMM.length = 4
166
+
167
+ MMDD = Field.new
168
+ MMDD.codec = MMDDCodec
169
+ MMDD.length = 4
170
+
171
+ Hhmmss = Field.new
172
+ Hhmmss.codec = HhmmssCodec
173
+ Hhmmss.length = 6
164
174
 
165
175
  end
@@ -147,9 +147,13 @@ module ISO8583
147
147
  # mes[2]=47474747 # bmp 2 is generally the PAN
148
148
  # mes["Primary Account Number"]=47474747 # if thats what you called the field in Message.bmp.
149
149
  def []=(key, value)
150
- bmp_def = _get_definition key
151
- bmp_def.value = value
152
- @values[bmp_def.bmp] = bmp_def
150
+ if value.nil?
151
+ @values.delete(key)
152
+ else
153
+ bmp_def = _get_definition key
154
+ bmp_def.value = value
155
+ @values[bmp_def.bmp] = bmp_def
156
+ end
153
157
  end
154
158
 
155
159
  # Retrieve the decoded value of the contents of a bitmap
@@ -1,4 +1,4 @@
1
1
  # -*- mode: ruby; encoding: utf-8; tab-width: 2; indent-tabs-mode: nil -*-
2
2
  module ISO8583
3
- VERSION = "0.1.5"
3
+ VERSION = "0.1.6"
4
4
  end
data/test/message_test.rb CHANGED
@@ -160,4 +160,14 @@ END
160
160
  mes2 = BerlinMessage.parse(mes.to_b)
161
161
  assert_equal(mes.to_b, mes2.to_b)
162
162
  end
163
+
164
+ def test_remove_field
165
+ mes = BerlinMessage.new
166
+ mes.mti = "Network Management Request Response Issuer Gateway or Acquirer Gateway"
167
+ mes[3] = nil
168
+
169
+ assert_nothing_raised do
170
+ mes.to_b
171
+ end
172
+ end
163
173
  end
data/test/test_codec.rb CHANGED
@@ -4,6 +4,24 @@ require 'lib/iso8583'
4
4
  include ISO8583
5
5
 
6
6
  class FieldTest < Test::Unit::TestCase
7
+ def test_hhmmssCodec
8
+ dt = HhmmssCodec.decode "121212"
9
+ assert_equal DateTime, dt.class
10
+ assert_equal 12, dt.hour
11
+ assert_equal 12, dt.min
12
+ assert_equal 12, dt.sec
13
+ assert_equal DateTime, dt.class
14
+
15
+ assert_raise(ISO8583Exception) {
16
+ dt = HhmmssCodec.decode "261212"
17
+ }
18
+ assert_raise(ISO8583Exception) {
19
+ dt = HhmmssCodec.encode "121261"
20
+ }
21
+ t = Time.new(2002, 10, 31, 2, 2, 2, "+02:00")
22
+ assert_equal "020202", HhmmssCodec.encode(t)
23
+
24
+ end
7
25
  def test_MMDDhhmmssCodec
8
26
  dt = MMDDhhmmssCodec.decode "1212121212"
9
27
  assert_equal DateTime, dt.class
@@ -12,6 +30,7 @@ class FieldTest < Test::Unit::TestCase
12
30
  assert_equal 12, dt.hour
13
31
  assert_equal 12, dt.min
14
32
  assert_equal 12, dt.sec
33
+ assert_equal DateTime, dt.class
15
34
 
16
35
  assert_raise(ISO8583Exception) {
17
36
  dt = MMDDhhmmssCodec.decode "1312121212"
@@ -62,6 +81,24 @@ class FieldTest < Test::Unit::TestCase
62
81
  assert_equal "0912", YYMMCodec.encode("0912")
63
82
  end
64
83
 
84
+ def test_YMMCodec
85
+ dt = MMDDCodec.decode "0812"
86
+ assert_equal DateTime, dt.class
87
+ assert_equal 8, dt.month
88
+ assert_equal 12, dt.day
89
+
90
+ assert_raise(ISO8583Exception) {
91
+ dt = MMDDCodec.decode "1313"
92
+ }
93
+
94
+ assert_raise(ISO8583Exception) {
95
+ dt = MMDDCodec.encode "0231"
96
+ }
97
+
98
+ assert_equal "0912", MMDDCodec.encode("0912")
99
+ t = Time.new(2002, 10, 31, 2, 2, 2, "+02:00")
100
+ assert_equal "1031", MMDDCodec.encode(t)
101
+ end
65
102
  def test_A_Codec
66
103
  assert_raise(ISO8583Exception) {
67
104
  dt = A_Codec.encode "!!!"
data/test/test_fields.rb CHANGED
@@ -234,4 +234,17 @@ class FieldTest < Test::Unit::TestCase
234
234
  fld = YYMMDDhhmmss
235
235
  assert_equal "740808120000", fld.encode("740808120000")
236
236
  end
237
+ def test_Hhmmss
238
+ fld = Hhmmss
239
+ assert_equal "123456", fld.encode("123456")
240
+ dt, rest = fld.parse("123456")
241
+ assert_equal 12, dt.hour
242
+ assert_equal 34, dt.min
243
+ assert_equal 56, dt.sec
244
+
245
+ assert_raise(ISO8583Exception) {
246
+ fld.encode 1234567
247
+ }
248
+
249
+ end
237
250
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: iso8583
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.5
4
+ version: 0.1.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tim Becker
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-01-26 00:00:00.000000000 Z
12
+ date: 2014-12-10 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: ! 'Ruby implementation of ISO 8583 financial messaging
15
15
 
@@ -21,6 +21,12 @@ executables: []
21
21
  extensions: []
22
22
  extra_rdoc_files: []
23
23
  files:
24
+ - AUTHORS
25
+ - CHANGELOG
26
+ - LICENSE
27
+ - README
28
+ - Rakefile
29
+ - TODO
24
30
  - lib/8583.rb
25
31
  - lib/iso8583.rb
26
32
  - lib/iso8583/berlin.rb
@@ -32,12 +38,6 @@ files:
32
38
  - lib/iso8583/message.rb
33
39
  - lib/iso8583/util.rb
34
40
  - lib/iso8583/version.rb
35
- - AUTHORS
36
- - CHANGELOG
37
- - LICENSE
38
- - README
39
- - Rakefile
40
- - TODO
41
41
  - test/BitmapTests.rb
42
42
  - test/message_test.rb
43
43
  - test/test_codec.rb
@@ -64,7 +64,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
64
64
  requirements:
65
65
  - none
66
66
  rubyforge_project: iso8583
67
- rubygems_version: 2.0.3
67
+ rubygems_version: 2.2.2
68
68
  signing_key:
69
69
  specification_version: 4
70
70
  summary: ! 'iso8583: Ruby implementation of ISO 8583 financial messaging'