Skip to content

Commit

Permalink
custom parsers: reduce cognitive complexity
Browse files Browse the repository at this point in the history
This is according to CodeClimate.
  • Loading branch information
dmke committed Jul 13, 2023
1 parent e1f9a63 commit 19da94a
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions lib/happymapper/item.rb
Original file line number Diff line number Diff line change
Expand Up @@ -118,19 +118,23 @@ def process_node_with_custom_parser(node)
node.to_s
end

custom_parser = options[:parser]
custom_parser = create_custom_parser(options[:parser])

begin
if custom_parser.respond_to?(:call)
custom_parser.call(value)
else
constant.send(custom_parser.to_sym, value)
end
custom_parser.call(value)
rescue StandardError
nil
end
end

def create_custom_parser(parser)
return parser if parser.respond_to?(:call)

proc { |value|
constant.send(parser.to_sym, value)
}
end

def process_node_with_default_parser(node, parse_options)
constant.parse(node, options.merge(parse_options))
end
Expand Down

0 comments on commit 19da94a

Please sign in to comment.