lib/beaker/options/options_hash.rb
# Recursively generate a string describing the contents of an object
#
# @param [Object] opts The Object to be described
# @param [String] pre  The format to pre-pend to described values
# @param [String] post The format to post-pend to described values
#
# @example
#   base = { :key => { :subkey1 => 'subval', :subkey2 => 'subval' } }
#   base.rdump == "\t\tkey :\n\t\t\tsubkey : subval\n\t\t\tsubkey2 : subval\n"
#      
# @return [String] The description of the Object 
Recursively generate a string describing the contents of an object
Recursively generate a string describing the contents of an object
def rdump(opts, pre=DIV, post="")
        str = ""
        if opts.kind_of?(Hash) || opts.kind_of?(OptionsHash)
          opts.each do |k, v|
            str += "#{pre + DIV}#{k.to_s} : "
            if v.kind_of?(Hash) || v.kind_of?(OptionsHash) 
              str += EOL
              str += rdump(v, "#{pre}#{DIV}", post)
            elsif v.kind_of?(Array) and not v.empty?
              str += EOL
              str += rdump(v, "#{pre}#{DIV}#{DIV}", post)
            else
              str += "#{v.to_s}#{post}#{EOL}"
            end
          end
        elsif opts.kind_of?(Array) 
          str += "#{pre}[#{EOL}"
          opts.each do |v|
            if not v.kind_of?(Array) and not v.kind_of?(Hash) and not v.kind_of?(OptionsHash)
              str += "#{pre}#{v.to_s},#{EOL}"
            else
              str += rdump(v, pre, ",")
            end
          end
          str += "#{pre}]#{EOL}"
        end
        str
      end
def rdump ( opts , pre = DIV , post = "" ) str = "" if opts . kind_of? ( Hash ) || opts . kind_of? ( OptionsHash ) opts . each do | k , v | str += "#{pre + DIV}#{k.to_s} : " if v . kind_of? ( Hash ) || v . kind_of? ( OptionsHash ) str += EOL str += rdump ( v , "#{pre}#{DIV}" , post ) elsif v . kind_of? ( Array ) and not v . empty? str += EOL str += rdump ( v , "#{pre}#{DIV}#{DIV}" , post ) else str += "#{v.to_s}#{post}#{EOL}" end end elsif opts . kind_of? ( Array ) str += "#{pre}[#{EOL}" opts . each do | v | if not v . kind_of? ( Array ) and not v . kind_of? ( Hash ) and not v . kind_of? ( OptionsHash ) str += "#{pre}#{v.to_s},#{EOL}" else str += rdump ( v , pre , "," ) end end str += "#{pre}]#{EOL}" end str end
Recursively generate a string describing the contents of an object
Recursively generate a string describing the contents of an object
The description of the Object
The description of the Object
String
opts
<not_specific>
pre
<not_specific>
post
<not_specific>
<not_specific>
post The format to post-pend to described values
post The format to post - pend to described values
example
base = { :key => { :subkey1 => 'subval', :subkey2 => 'subval' } } base.rdump == "\t\tkey :\n\t\t\tsubkey : subval\n\t\t\tsubkey2 : subval\n"
base = { : key = > { : subkey1 = > ' subval ' : subkey2 = > ' subval ' } } base . rdump == " \ t \ tkey : \ n \ t \ t \ tsubkey : subval \ n \ t \ t \ tsubkey2 : subval \ n "