-
Notifications
You must be signed in to change notification settings - Fork 5
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
adding support for XML parsing and shale type mapping #48
base: main
Are you sure you want to change the base?
Changes from all commits
198e028
bec7c04
009dce6
b73b011
abc01c3
2a9f38b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,3 +8,4 @@ inherit_from: | |
|
||
AllCops: | ||
TargetRubyVersion: 2.5 | ||
NewCops: enable |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
require "lutaml/xml/parsers/xml" | ||
|
||
require "lutaml/xml/mapper" | ||
require "lutaml/xml/lutaml_path/document_wrapper" | ||
|
||
require "shale" | ||
require "shale/adapter/nokogiri" | ||
|
||
Shale.xml_adapter = Shale::Adapter::Nokogiri |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
require "lutaml/lutaml_path/document_wrapper" | ||
|
||
module Lutaml | ||
module Xml | ||
module LutamlPath | ||
class DocumentWrapper < ::Lutaml::LutamlPath::DocumentWrapper | ||
protected | ||
|
||
def serialize_document(document) | ||
serialize_to_hash(document) | ||
end | ||
|
||
def serialize_to_hash(object) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Assignment Branch Condition size for serialize_to_hash is too high. [<11, 45, 15> 48.69/15] |
||
hash = {} | ||
attribute_name = nil | ||
|
||
object.all_content.each do |mapping, content| | ||
if mapping == "content" | ||
attribute_name = object.class.xml_mapping.content.attribute.to_s | ||
hash[attribute_name] ||= [] | ||
hash[attribute_name] << content.strip unless content.strip&.empty? | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Avoid calling empty? with the safe navigation operator in conditionals. |
||
elsif content.is_a?(String) | ||
if object.class.attributes[mapping.attribute].collection? | ||
hash[mapping.name] ||= [] | ||
hash[mapping.name] << content.strip | ||
else | ||
hash[mapping.name] = content.strip | ||
end | ||
else | ||
if object.class.attributes[mapping.attribute].collection? | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Convert if nested inside else to elsif. |
||
hash[mapping.name] ||= [] | ||
hash[mapping.name] << serialize_to_hash(content) | ||
else | ||
hash[mapping.name] = serialize_to_hash(content) | ||
end | ||
end | ||
end | ||
|
||
hash[attribute_name] = hash[attribute_name].compact if attribute_name | ||
hash | ||
end | ||
end | ||
end | ||
end | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Assignment Branch Condition size for serialize_to_hash is too high. [<11, 45, 16> 49.01/15]
Cyclomatic complexity for serialize_to_hash is too high. [13/6]
Method has too many lines. [25/10]
Perceived complexity for serialize_to_hash is too high. [16/7]