Module: RazorRisk::Cassini::Util::ConversionUtil
- Includes:
- RazorRisk::Core::Diagnostics::Logger, Xqsr3::Quality::ParameterChecking
- Defined in:
- lib/razor_risk/cassini/util/conversion_util.rb
Defined Under Namespace
Modules: ConversionUtil_Constants
Class Method Summary collapse
Instance Method Summary collapse
-
#convert_XML_to_Hash(xml, **options) ⇒ Object
Converts XML to a Hash.
-
#convert_XML_to_JSON(xml, **options) ⇒ Object
Converts XML to a JSON.
Class Method Details
.included(receiver) ⇒ Object
48 49 50 51 |
# File 'lib/razor_risk/cassini/util/conversion_util.rb', line 48 def self.included receiver receiver.extend self end |
Instance Method Details
#convert_XML_to_Hash(xml, **options) ⇒ Object
Converts XML to a Hash
Signature
- Options:
@option
:scheme:: The scheme to use for the conversion. May be:default,:gdataornil, ifnilthe:defaultscheme is used.
Return
A hash representing the supplied XML.
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/razor_risk/cassini/util/conversion_util.rb', line 64 def convert_XML_to_Hash xml, ** check_parameter xml, 'xml', types: [ ::Nokogiri::XML::Node, ::String ] scheme = check_option , :scheme, type: ::Symbol, allow_nil: true, values: ConversionUtil_Constants::XML_to_JSON_Schemes scheme ||= :default case scheme when :gdata xml_to_gdata_hash_ xml when :default xml_to_hash_ xml else log :violation, "invalid scheme '#{scheme}'" end end |
#convert_XML_to_JSON(xml, **options) ⇒ Object
Converts XML to a JSON
Signature
- Options:
@option
:scheme:: The scheme to use for the conversion. May be:default,:gdataornil, ifnilthe:defaultscheme is used.
Return
The supplied XML in JSON format.
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 |
# File 'lib/razor_risk/cassini/util/conversion_util.rb', line 94 def convert_XML_to_JSON xml, ** check_parameter xml, 'xml', types: [ ::Hash, ::Nokogiri::XML::Node, ::String ] case xml when ::Hash h = xml else h = convert_XML_to_Hash xml, end JSON.generate(h) end |