Created
September 1, 2021 10:54
-
-
Save goromlagche/69f04033575bac9baa67bf289399953b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'nori' | |
single_comment = <<~EOF | |
<?xml version="1.0" encoding="UTF-8"?> | |
<comments> | |
<comment> | |
<description>TEST COMMENT 123</description> | |
</comment> | |
</comments> | |
EOF | |
multiple_comments = <<~EOF | |
<?xml version="1.0" encoding="UTF-8"?> | |
<comments> | |
<comment> | |
<description>TEST COMMENT 123</description> | |
</comment> | |
<comment> | |
<description>TEST COMMENT 456</description> | |
</comment> | |
</comments> | |
EOF | |
def fetch_descriptions_1(raw_data:) | |
comments = Nori.new.parse(raw_data)['comments']['comment'] | |
if comments.is_a?(Array) | |
comments.map { |comment| comment['description'] } | |
else | |
[comments['description']] | |
end | |
end | |
def fetch_descriptions_2(raw_data:) | |
comments = [Nori.new.parse(raw_data)['comments']['comment']].flatten | |
comments.map { |comment| comment['description'] } | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment