tree_decorator 0.1.7 → 0.1.8

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ YmFjMWRlZTZkNmUzZGRkNTViODlkMWM1ZDE1Nzk2ZTdkMzY5Y2ZmNQ==
5
+ data.tar.gz: !binary |-
6
+ MzIzNmRmODE2ZTM0ZTVlMWJmNzMxMTJlMDgxOGEyZDYwODJiNDEyNw==
7
+ SHA512:
8
+ metadata.gz: !binary |-
9
+ YTRlM2RkMmU2NTFiN2M5YzM0ZTNhMWMwYWMzMTI5YjQzZTZhOTkyMzkwY2Zk
10
+ ZDUwMzlhZjE1NTkyYmRlODQ3NTYwOWNlZmU2MjFkMDMzMTAwZDc1ZmEyNGVi
11
+ OGNlZjBjYTdlNTdlY2Q5MTkzMzQ3ZjUzYTQ3N2QzYTA0MTQ1ZDE=
12
+ data.tar.gz: !binary |-
13
+ NmE0Mjg3ZTdkY2NjNzk4NzQxYmU1NjEyOWU3ZmMyN2QyZTlkOGUyOGI5ZmRj
14
+ MzIxMGNjNWM1MTU4MDdjZGM4M2UwODZiYzRiMzgwYmExNzg2YmI2ZmY4NjZh
15
+ ZWRkY2U4YzM5YzRlZWViYjczZDFmZmY3ZWQ0ZDJjZjA2NGU1ODE=
data/lib/example.rb CHANGED
@@ -3,12 +3,12 @@ require_relative('tree_decorator')
3
3
  tree = {
4
4
  1 => {
5
5
  2 => {
6
- 4 => {},
7
- 5 => {},
6
+ 3 => 4,
7
+ 5 => 6,
8
8
  },
9
- 6 => {}
9
+ 7 => 8
10
10
  },
11
- 7 => {}
11
+ 9 => 10
12
12
  }
13
13
 
14
14
  hanger = TreeDecorator::Hanger.new(tree)
@@ -19,10 +19,9 @@ hanger.inner {|content| "<li>#{content}<li>"}
19
19
  puts unordered_list = hanger.tree
20
20
 
21
21
  hanger = TreeDecorator::Hanger.new(tree)
22
+ hanger.inner {|content| "<inner>#{content}</inner>"}
23
+ hanger.outer {|content| "<outer>#{content}</outer>"}
22
24
  hanger.element {|content| "element:#{content}"}
23
- hanger.outer {|content| "<container>#{content}</container>"}
24
- hanger.join_with(',')
25
-
26
25
  puts containers = hanger.tree
27
26
 
28
27
 
@@ -29,9 +29,16 @@ module TreeDecorator
29
29
 
30
30
  private
31
31
  def packager(hash)
32
+ hash = hash.to_hash if hash.respond_to? :to_hash
33
+ unless hash.kind_of? Hash
34
+ hash = @element.call(hash) if @element
35
+ return @inner ? @inner.call(hash) : hash
36
+ end
32
37
  output = []
33
38
  hash.each do |parent, child|
34
39
  parent = @element.call(parent) if @element
40
+ child = child.to_hash if child.respond_to? :to_hash
41
+ child = child.to_s unless child.kind_of? Hash
35
42
  if child and !child.empty?
36
43
  child = packager(child)
37
44
  child = @outer.call(child) if @outer
metadata CHANGED
@@ -1,15 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tree_decorator
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.7
5
- prerelease:
4
+ version: 0.1.8
6
5
  platform: ruby
7
6
  authors:
8
7
  - Rob Nichols
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2012-08-28 00:00:00.000000000Z
11
+ date: 2012-08-28 00:00:00.000000000 Z
13
12
  dependencies: []
14
13
  description: A tool that walks through a hash or nested object and applies code to
15
14
  containers and elements based on user defined rules.
@@ -20,32 +19,31 @@ extra_rdoc_files: []
20
19
  files:
21
20
  - README.md
22
21
  - LICENSE
22
+ - lib/example.rb
23
23
  - lib/tree_decorator.rb
24
- - lib/tree_decorator/object_hanger.rb
25
24
  - lib/tree_decorator/hanger.rb
26
- - lib/example.rb
25
+ - lib/tree_decorator/object_hanger.rb
27
26
  homepage: https://github.com/reggieb/TreeDecorator
28
27
  licenses: []
28
+ metadata: {}
29
29
  post_install_message:
30
30
  rdoc_options: []
31
31
  require_paths:
32
32
  - lib
33
33
  required_ruby_version: !ruby/object:Gem::Requirement
34
- none: false
35
34
  requirements:
36
35
  - - ! '>='
37
36
  - !ruby/object:Gem::Version
38
37
  version: '0'
39
38
  required_rubygems_version: !ruby/object:Gem::Requirement
40
- none: false
41
39
  requirements:
42
40
  - - ! '>='
43
41
  - !ruby/object:Gem::Version
44
42
  version: '0'
45
43
  requirements: []
46
44
  rubyforge_project:
47
- rubygems_version: 1.8.10
45
+ rubygems_version: 2.1.10
48
46
  signing_key:
49
- specification_version: 3
47
+ specification_version: 4
50
48
  summary: Tree Decorator decorates trees or nested sets of data
51
49
  test_files: []