lib/origen/parameters/set.rb in origen-0.24.0 vs lib/origen/parameters/set.rb in origen-0.25.0

- old
+ new

@@ -151,8 +151,36 @@ def live owner._request_live_parameter self end + + def to_flat_hash(options = {}) + options = { + delimiter: '.' + }.update(options) + flatten_params(self, options[:delimiter]).first + end + + private + + def flatten_params(param_hash, delimiter, name = nil, results_hash = {}) + param_hash.each do |k, v| + if v.is_a? Origen::Parameters::Set + name.nil? ? name = k.to_s : name << "#{delimiter}#{k}" + (results_hash, name) = flatten_params(v, delimiter, name, results_hash) + else + if name.nil? + results_hash[k] = v + else + results_hash["#{name}#{delimiter}#{k}"] = v + if k == param_hash.keys.last + name = nil + end + end + end + end + [results_hash, name] + end end end end