# frozen_string_literal: true module Cryptum # Load in a Data Structure and Convert Strings to Integers or Floats if Possible. module Massage # Supported Method Parameters:: # number = numeric( # struct: 'required - data structure to massage' # ) private_class_method def self.numeric(opts = {}) struct = opts[:struct] Integer(struct) rescue StandardError Float(struct) end # Supported Method Parameters:: # massaged_data = Cryptum::Massage.data( # struct: 'required - data structure to massage' # ) public_class_method def self.data(opts = {}) struct = opts[:struct] case struct when String begin numeric(struct: struct) rescue StandardError struct end when Array struct.map { |i| data(struct: i) } when Hash struct.merge(struct) { |_k, v| data(struct: v) } else struct end rescue Interrupt, StandardError => e Cryptum::Log.append(level: :error, msg: e, which_self: self) end # Display Usage for this Module public_class_method def self.help puts "USAGE: massaged_data = Cryptum::Massage.data( struct: 'required - data structure to massage' ) " end end end