swifty 0.0.5 → 0.0.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 +4 -4
- data/lib/swifty.rb +32 -2
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 737b34d01da59b81b34ec29ab88c09ad78339ebc
|
4
|
+
data.tar.gz: b50c80949b0da88041b100b42eb2b958a2368041
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 98244fcdb1311796206efa0708756b0d94e1986ba57436abfd3ee8b04a7db91115e3343519d6759086e933ff66794efdbd2d1b721d099bc8f28e4083f39b4c36
|
7
|
+
data.tar.gz: 811b29b6624fd9d1e1a78f9d2c94f520049a268fc7587f61a91e7918be8301c39aff5046a28e383e419be1c6370f075ab11c9b3da9e594d0deaad1ce2b816d49
|
data/lib/swifty.rb
CHANGED
@@ -1,14 +1,44 @@
|
|
1
1
|
require 'active_support/all'
|
2
2
|
require 'cmxl'
|
3
|
-
require_relative 'cmxl/header'
|
4
3
|
require 'choice'
|
5
4
|
require 'pp'
|
6
5
|
require 'yaml'
|
7
|
-
|
6
|
+
|
7
|
+
NoFile = Class.new(StandardError)
|
8
8
|
|
9
9
|
Cmxl.config[:statement_separator] = /-\}/m
|
10
10
|
Cmxl.config[:raise_line_format_errors] = true
|
11
11
|
|
12
|
+
module Cmxl
|
13
|
+
# Field parser to handle the header field.
|
14
|
+
class HeaderFieldParser < Cmxl::Field
|
15
|
+
self.tag = 1
|
16
|
+
|
17
|
+
# Parses the line into two groups: (1) basic_header and (2) application_header
|
18
|
+
self.parser = /1:(?<basic_header>([^}]+))}{2:(?<application_header>([^}]+))/
|
19
|
+
end
|
20
|
+
|
21
|
+
class Field
|
22
|
+
# Override for https://github.com/railslove/cmxl/blob/master/lib/cmxl/field.rb#L46-L53
|
23
|
+
#
|
24
|
+
# This ensures that we can parse the header (field 1, 2, and 3) in the SWIFT messages. See the example.swift.txt for
|
25
|
+
# an example.
|
26
|
+
#
|
27
|
+
# See also http://ibm.co/1K0zURs
|
28
|
+
def self.parse(line)
|
29
|
+
if line.match(/^:(\d{2,2})(\w)?:(.*)$/)
|
30
|
+
tag, modifier, content = $1, $2, $3
|
31
|
+
Field.parsers[tag.to_s].new(content, modifier, tag)
|
32
|
+
elsif line.match Regexp.new('\d:([^}]+)') # Header
|
33
|
+
basic_header, application_header = $1, $2
|
34
|
+
Field.parsers['1'].new(basic_header, application_header, '1')
|
35
|
+
else
|
36
|
+
raise LineFormatError, "Wrong line format: #{line.dump}" if Cmxl.config[:raise_line_format_errors]
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
12
42
|
class Swifty
|
13
43
|
attr_reader :content, :options, :statement
|
14
44
|
|