Sha256: fbf956d66734d1bd724bd33d5476c2b7735fc7009a408ebc7760149af07fb841

Contents?: true

Size: 1.07 KB

Versions: 22

Compression:

Stored size: 1.07 KB

Contents

module PoolParty
  class HashPrinter
    def self.print_to_string(props={})
<<-EOE
Top Level
  #{print_hash(props, 1)}
EOE
    end
    def self.print_hash(props={}, tabs=0)
      out = []
      if props[:options]
        out << props[:options].map {|k,v| "#{print_tabs(tabs)}#{k} => #{print_value(v)}"}.join("#{print_tabs(tabs)}\n")
      end
      if props[:resources]
        props[:resources].each do |ty,r|
          out << [
            "#{print_tabs(tabs)}#{ty.to_s.capitalize}",
            r.map {|h| h.map {|k,v| "#{print_tabs(tabs+1)}#{k} => #{print_value(v)}"}}.join("#{print_tabs(tabs+1)}\n")
          ].join("\n")
        end
      end
      if props[:services]
        props[:services].each do |nm,s|
          out << [
            "#{print_tabs(tabs)}#{nm.to_s.capitalize}",
            print_hash(s,tabs+1)
          ].join("\n")
        end
      end
      out.join("\n")
    end
    def self.print_tabs(tabs=1)
      "#{"\t"*tabs}"
    end
    def self.print_value(v)
      case v
      when Array
        "[#{v.join(", ")}]"
      else
        v
      end
    end
  end
end

Version data entries

22 entries across 22 versions & 3 rubygems

Version Path
auser-poolparty-1.1.1 lib/poolparty/helpers/hash_printer.rb
auser-poolparty-1.1.3 lib/poolparty/helpers/hash_printer.rb
auser-poolparty-1.1.4 lib/poolparty/helpers/hash_printer.rb
auser-poolparty-1.1.5 lib/poolparty/helpers/hash_printer.rb
auser-poolparty-1.1.6 lib/poolparty/helpers/hash_printer.rb
auser-poolparty-1.1.7 lib/poolparty/helpers/hash_printer.rb
auser-poolparty-1.2.0 lib/poolparty/helpers/hash_printer.rb
auser-poolparty-1.2.1 lib/poolparty/helpers/hash_printer.rb
auser-poolparty-1.2.10 lib/poolparty/helpers/hash_printer.rb
auser-poolparty-1.2.11 lib/poolparty/helpers/hash_printer.rb
auser-poolparty-1.2.12 lib/poolparty/helpers/hash_printer.rb
auser-poolparty-1.2.2 lib/poolparty/helpers/hash_printer.rb
auser-poolparty-1.2.3 lib/poolparty/helpers/hash_printer.rb
auser-poolparty-1.2.4 lib/poolparty/helpers/hash_printer.rb
auser-poolparty-1.2.7 lib/poolparty/helpers/hash_printer.rb
auser-poolparty-1.2.8 lib/poolparty/helpers/hash_printer.rb
auser-poolparty-1.2.9 lib/poolparty/helpers/hash_printer.rb
fairchild-poolparty-1.1.3 lib/poolparty/helpers/hash_printer.rb
fairchild-poolparty-1.1.4 lib/poolparty/helpers/hash_printer.rb
fairchild-poolparty-1.1.5 lib/poolparty/helpers/hash_printer.rb