swifty 0.0.5 → 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/swifty.rb +32 -2
  3. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 95b07b77a6a8991ff92031eea0e8ede1aad07ed2
4
- data.tar.gz: 7d89d50499e35d57030a6928ff58b0a54e3b7dec
3
+ metadata.gz: 737b34d01da59b81b34ec29ab88c09ad78339ebc
4
+ data.tar.gz: b50c80949b0da88041b100b42eb2b958a2368041
5
5
  SHA512:
6
- metadata.gz: 30bd1016f388ea2f24b9d719de81ad1777f3a8ae05ffc4ef0d926ef432a4ec0374e951f3ef100e367b4a4ae317920286043a82df8b0be03e74c330b839527b54
7
- data.tar.gz: 8371929da3661e0aa365a1a94decac17cf3ce3681b9f16fb434950bffca063382e7c7244fa9a3524909a5b4e12b15e714403a5d68aea0f6cfd51c009d0cafcc6
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
- require_relative 'exceptions'
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
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: swifty
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Emil Kampp