clean-my-vomit 0.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/clean-my-vomit.rb +46 -0
- metadata +46 -0
@@ -0,0 +1,46 @@
|
|
1
|
+
module CleanMyVomit
|
2
|
+
def polish(my_hash=self, depth=0)
|
3
|
+
if !reached_max_recursion_depth?(my_hash)
|
4
|
+
my_hash.each do |key, value|
|
5
|
+
if value.is_a? Hash
|
6
|
+
print_hash(key, value, depth)
|
7
|
+
elsif value.is_a? Array
|
8
|
+
print_array(key, value, depth)
|
9
|
+
else
|
10
|
+
if key.is_a? Hash
|
11
|
+
puts " "*depth + " {"
|
12
|
+
polish(key, depth + 3)
|
13
|
+
puts " "*depth + " }"
|
14
|
+
elsif value
|
15
|
+
puts " "*depth + key + " => #{value}"
|
16
|
+
else
|
17
|
+
puts " "*depth + key.to_s + ""
|
18
|
+
end
|
19
|
+
polish(value, depth + 3)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
private
|
26
|
+
def reached_max_recursion_depth?(my_object)
|
27
|
+
!(my_object.respond_to? :each)
|
28
|
+
end
|
29
|
+
|
30
|
+
# {"3" => { "3" => "2"}}
|
31
|
+
def print_hash(key, value, depth)
|
32
|
+
puts " "*depth + key + " {"
|
33
|
+
polish(value, depth + 3)
|
34
|
+
puts " "*depth + "}"
|
35
|
+
end
|
36
|
+
|
37
|
+
# { "3" => [3,2,3]}
|
38
|
+
def print_array(key, value, depth)
|
39
|
+
puts " "*depth + key + " =>["
|
40
|
+
polish(value, depth + 3)
|
41
|
+
puts " "*depth + "]"
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
Hash.send(:include, CleanMyVomit)
|
46
|
+
Array.send(:include, CleanMyVomit)
|
metadata
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: clean-my-vomit
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Dylan Drop
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-06-19 00:00:00.000000000Z
|
13
|
+
dependencies: []
|
14
|
+
description: Ruby gem that makes your long, deeply nested hashes easily displayable
|
15
|
+
on command-line.
|
16
|
+
email: dylandrop@gmail.com
|
17
|
+
executables: []
|
18
|
+
extensions: []
|
19
|
+
extra_rdoc_files: []
|
20
|
+
files:
|
21
|
+
- lib/clean-my-vomit.rb
|
22
|
+
homepage: http://rubygems.org/gems/clean-my-vomit
|
23
|
+
licenses: []
|
24
|
+
post_install_message:
|
25
|
+
rdoc_options: []
|
26
|
+
require_paths:
|
27
|
+
- lib
|
28
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
29
|
+
none: false
|
30
|
+
requirements:
|
31
|
+
- - ! '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
35
|
+
none: false
|
36
|
+
requirements:
|
37
|
+
- - ! '>='
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '0'
|
40
|
+
requirements: []
|
41
|
+
rubyforge_project:
|
42
|
+
rubygems_version: 1.8.13
|
43
|
+
signing_key:
|
44
|
+
specification_version: 3
|
45
|
+
summary: Clean
|
46
|
+
test_files: []
|