Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lg/fix failure when parsing empty details #28

Merged
merged 3 commits into from
Dec 30, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cfonb.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

Gem::Specification.new do |s|
s.name = 'cfonb'
s.version = '1.1.0'
s.version = '1.1.1'
s.required_ruby_version = '>= 3.2'
s.summary = 'CFONB parser'
s.description = 'An easy to use CFONB format parser'
Expand Down
2 changes: 1 addition & 1 deletion lib/cfonb/operation_details.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def self.register(code, klass)
end

def self.for(line)
return unless line.respond_to?(:detail_code)
return unless line.respond_to?(:detail_code) && line.detail_code != ''

@details[line.detail_code] || Unknown
end
Expand Down
2 changes: 1 addition & 1 deletion lib/cfonb/operation_details/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ def self.inherited(base)
base.singleton_class.prepend(
Module.new do
def apply(details, line)
code = :"@#{line.detail_code}"
code = :"@#{line.detail_code.gsub(' ', '_')}"
details.instance_variable_set(code, instance_value(details, line, code))

super
Expand Down
2 changes: 1 addition & 1 deletion lib/cfonb/operation_details/unknown.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class Unknown < Base

def self.apply(details, line)
details.unknown ||= {}
code = line.detail_code
code = line.detail_code.gsub(' ', '_')

details.unknown[code] =
if details.unknown[code] && line.detail.is_a?(String)
Expand Down
1 change: 1 addition & 0 deletions spec/cfonb/parser_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
'AAA' => "INTERNETA AAA\nINTERNETA ABB",
'BBB' => 'INTERNETE BBB',
'CCC' => 'INTERNETI CCC',
'N_Y' => 'EXAMPLE WITH EMPTY SPACE',
},
)

Expand Down
2 changes: 2 additions & 0 deletions spec/files/example.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
0515589916200000EUR2 98765432100B1160519 AAAINTERNETA ABB
0515589916200000EUR2 98765432100B1160519 BBBINTERNETE BBB
0515589916200000EUR2 98765432100B1160519 CCCINTERNETI CCC
0515589916200000EUR2 98765432100B1160519
0515589916200000EUR2 98765432100B1160519 N YEXAMPLE WITH EMPTY SPACE

0415589916200000EUR2 98765432100B1160519 160519VIR SEPA DEMONSTRATION 0000000000000000000107}REFERENCE
0515589916200000EUR2 98765432100B1160519 NPYELEC ERDF
Expand Down