Class: Hbci::Parser
- Inherits:
-
Object
- Object
- Hbci::Parser
- 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
-
#scanner ⇒ Object
readonly
Returns the value of attribute scanner.
-
#segments ⇒ Object
Returns the value of attribute segments.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(string) ⇒ Parser
constructor
A new instance of Parser.
- #parse ⇒ Object
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
#scanner ⇒ Object (readonly)
Returns the value of attribute scanner.
5 6 7 |
# File 'lib/hbci/parser.rb', line 5 def scanner @scanner end |
#segments ⇒ Object
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
#parse ⇒ Object
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 |