Class: Hbci::Parser

Inherits:
Object
  • Object
show all
Defined in:
lib/hbci/parser.rb

Constant Summary collapse

ELEMENT_DELIMITER =
':'
ELEMENT_GROUP_DELIMITER =
'+'
SEGMENT_DELIMITER =
'\''
ELEMENT_REGEX =

ELEMENT_REGEX matches everything until a a delimiter that is not escaped

NODE EXPLANATION


(                        group and capture to \1:

.*?                      any character except \n (0 or more times
                         (matching the least amount possible))

(?=                      look ahead to see if there is:

(?<!                     look behind to see if there is not:

\?                       '?'

)                        end of look-behind

[:+']                    any character of: ':', '+', '''

)                        end of look-ahead

)                        end of \1
/(.*?(?=(?<!\?)[:+']))/.freeze
BINARY_ELEMENT_LENGTH_REGEX =

Binary Elements may contain unescaped delimiters. Thus they are not terminated by regular delimiters. But their content is preceeded with its length surrounded by ‘@’s. e.g.:

‘@6@mydata’ or ‘@12@mydatamydata’

The BINARY_ELEMENT_LENGTH_REGEx matches only the length.

/@(\d+)@/.freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(string) ⇒ Parser

Returns a new instance of Parser.



49
50
51
52
53
54
# File 'lib/hbci/parser.rb', line 49

def initialize(string)
  @scanner = StringScanner.new(string)
  @segments = []
  add_segment
  add_element_group
end

Instance Attribute Details

#scannerObject (readonly)

Returns the value of attribute scanner.



5
6
7
# File 'lib/hbci/parser.rb', line 5

def scanner
  @scanner
end

#segmentsObject

Returns the value of attribute segments.



6
7
8
# File 'lib/hbci/parser.rb', line 6

def segments
  @segments
end

Class Method Details

.parse(string) ⇒ Object



45
46
47
# File 'lib/hbci/parser.rb', line 45

def self.parse(string)
  new(string).parse
end

Instance Method Details

#parseObject



56
57
58
59
60
61
62
63
# File 'lib/hbci/parser.rb', line 56

def parse
  parse_element
  while scanner.rest_size > 1
    parse_delimiter
    parse_element
  end
  segments
end