tree_hierarchy 1.0.0 → 2.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.
- checksums.yaml +4 -4
- data/lib/helper/support_method.rb +14 -3
- data/lib/hierarchy/added_hierarchy_level.rb +71 -49
- data/lib/hierarchy/hierarchy_no_level.rb +3 -3
- data/lib/hierarchy/hierarchy_with_level.rb +21 -3
- metadata +5 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 86e5d35dc28014de283c41a8a4d1e83fba1e859a
|
4
|
+
data.tar.gz: 51dd70bd650b5e10e6dc0f7f0f7dbeaed923db08
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3a8a5553c660f79e8b53ab1bb8735d0b27e81a62a548766c4128b42ee07e5c49b896796bf30f469eab062c3ac6a280a3d21e7966380a2ad359f0a52cc87b07b5
|
7
|
+
data.tar.gz: be6fec718b992fccc79a97031b7325de17468c28c837ffc1dc62bf002b1fa011bd27d413574378ae86f808cc57412908b12cf90569eabeedbf68ed1d4838bf35
|
@@ -1,11 +1,22 @@
|
|
1
1
|
module SupportMethod
|
2
2
|
|
3
|
-
def group_result_set(result_set)
|
4
|
-
result_set.group_by
|
3
|
+
def group_result_set(result_set)
|
4
|
+
result_set.group_by{|x| x.parent_id ? x.parent_id.to_i : x.parent_id }
|
5
5
|
end
|
6
6
|
|
7
7
|
def total_calc(result_group,field_set)
|
8
|
-
result_group.sum{|x| x[field_set].
|
8
|
+
result_group.sum{|x| x[field_set].to_f}
|
9
|
+
end
|
10
|
+
|
11
|
+
def presence_check(value)
|
12
|
+
value.blank?
|
13
|
+
end
|
14
|
+
|
15
|
+
def level_check(value)
|
16
|
+
value == 0
|
9
17
|
end
|
10
18
|
|
19
|
+
def compare(arg1,arg2)
|
20
|
+
arg1 > arg2
|
21
|
+
end
|
11
22
|
end
|
@@ -1,76 +1,98 @@
|
|
1
1
|
module AddedHierarchyLevel
|
2
2
|
|
3
3
|
@@result_group = []
|
4
|
+
@@linear = []
|
4
5
|
|
5
|
-
def added_hierarchy(result_set,depth = 0
|
6
|
+
def added_hierarchy(result_set,args,depth = 0)
|
6
7
|
@@result_group = group_result_set(result_set)
|
7
8
|
parent_child_add(args)
|
8
|
-
(depth
|
9
|
+
level_check(depth) ? self.tree_structure(result_set,@@result_group) : self.tree_structure_depth(result_set,@@result_group,depth.to_i)
|
9
10
|
end
|
10
11
|
|
11
|
-
def added_hierarchy_level(result_set,depth = 0
|
12
|
+
def added_hierarchy_level(result_set,args,depth = 0)
|
12
13
|
@@result_group = group_result_set(result_set)
|
13
14
|
parent_child_add(args)
|
14
|
-
(depth
|
15
|
+
level_check(depth) ? self.tree_structure_level(result_set,@@result_group) : self.tree_structure_depth_level(result_set,@@result_group,depth.to_i)
|
16
|
+
end
|
17
|
+
|
18
|
+
def added_hchildren(result_set,args)
|
19
|
+
@@result_group = group_result_set(result_set)
|
20
|
+
parent_child_add(args)
|
21
|
+
self.hchildren_structure(result_set,@@result_group)
|
22
|
+
end
|
23
|
+
|
24
|
+
def added_hchildren_ids(result_set,args)
|
25
|
+
@@result_group = group_result_set(result_set)
|
26
|
+
parent_child_add(args)
|
27
|
+
self.hchildren_structure_ids(result_set,@@result_group)
|
15
28
|
end
|
16
29
|
|
17
|
-
def
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
when 2
|
23
|
-
calc_of_parent_two(field_set)
|
24
|
-
when 3
|
25
|
-
calc_of_parent_three(field_set)
|
26
|
-
when 4
|
27
|
-
calc_of_parent_four(field_set)
|
28
|
-
else
|
29
|
-
calc_of_parent_five(field_set)
|
30
|
-
end
|
30
|
+
def linear_level(result_set,depth = 0)
|
31
|
+
@@linear = []
|
32
|
+
result_group = group_result_set(result_set)
|
33
|
+
level_check(depth) ? self.linear_structure_level(result_set,result_group) : self.linear_structure_depth_level(result_set,result_group,depth.to_i)
|
34
|
+
return @@linear
|
31
35
|
end
|
32
36
|
|
33
|
-
|
34
|
-
|
37
|
+
def linear(result_set,depth = 0)
|
38
|
+
@@linear = []
|
39
|
+
result_group = group_result_set(result_set)
|
40
|
+
level_check(depth) ? self.linear_structure(result_set,result_group) : self.linear_structure_depth(result_set,result_group,depth.to_i)
|
41
|
+
return @@linear
|
42
|
+
end
|
35
43
|
|
36
|
-
def
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
44
|
+
def added_linear(result_set,args,depth = 0)
|
45
|
+
@@linear = []
|
46
|
+
@@result_group = group_result_set(result_set)
|
47
|
+
parent_child_add(args)
|
48
|
+
level_check(depth) ? self.linear_structure(result_set,@@result_group) : self.linear_structure_depth(result_set,@@result_group,depth.to_i)
|
49
|
+
return @@linear
|
42
50
|
end
|
43
51
|
|
44
|
-
def
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
52
|
+
def added_linear_level(result_set,args,depth = 0)
|
53
|
+
@@linear = []
|
54
|
+
@@result_group = group_result_set(result_set)
|
55
|
+
parent_child_add(args)
|
56
|
+
level_check(depth) ? self.linear_structure_level(result_set,@@result_group) : self.linear_structure_depth_level(result_set,@@result_group,depth.to_i)
|
57
|
+
return @@linear
|
58
|
+
end
|
59
|
+
|
60
|
+
def parent_child_add(field_set)
|
61
|
+
unless presence_check(@@result_group[self.id])
|
62
|
+
@@result_group[self.id].map{|x| x.parent_child_add(field_set)}
|
63
|
+
@@result_group[self.parent_id].each do|x|
|
64
|
+
next unless x.id == self.id
|
65
|
+
for i in 0..field_set.length-1
|
66
|
+
x[field_set[i]] = total_calc(@@result_group[self.id],field_set[i])
|
67
|
+
end
|
68
|
+
end
|
49
69
|
end
|
50
70
|
end
|
51
71
|
|
52
|
-
def
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
@@result_group[self.parent_id].map{|x| (x.id == self.id) && (x[field_set[0]] = sum_value0) && (x[field_set[1]] = sum_value1) && (x[field_set[2]] = sum_value2)}
|
57
|
-
end
|
72
|
+
def linear_structure_level(result_set,result_group,increment = 1)
|
73
|
+
self.attributes.merge(:level => increment)
|
74
|
+
@@linear << self
|
75
|
+
result_group[self.id].map{|x| x.linear_structure_level(result_set,result_group,increment+1)} unless presence_check(result_group[self.id])
|
58
76
|
end
|
59
77
|
|
60
|
-
def
|
61
|
-
unless
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
end
|
78
|
+
def linear_structure_depth_level(result_set,result_group,depth,increment = 1)
|
79
|
+
unless compare(increment,depth)
|
80
|
+
self.attributes.merge({:level => increment})
|
81
|
+
@@linear << self
|
82
|
+
result_group[self.id].map{|x| x.linear_structure_depth(result_set,result_group,depth,increment + 1)} unless presence_check(result_group[self.id])
|
83
|
+
end
|
66
84
|
end
|
67
85
|
|
68
|
-
def
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
86
|
+
def linear_structure(result_set,result_group)
|
87
|
+
@@linear << self
|
88
|
+
result_group[self.id].map{|x| x.linear_structure(result_set,result_group)} unless presence_check(result_group[self.id])
|
89
|
+
end
|
90
|
+
|
91
|
+
def linear_structure_depth(result_set,result_group,depth,increment = 1)
|
92
|
+
unless compare(increment,depth)
|
93
|
+
@@linear << self
|
94
|
+
result_group[self.id].map{|x| x.linear_structure_depth(result_set,result_group,depth,increment + 1)} unless presence_check(result_group[self.id])
|
95
|
+
end
|
74
96
|
end
|
75
97
|
|
76
98
|
end
|
@@ -2,15 +2,15 @@ module HierarchyNoLevel
|
|
2
2
|
|
3
3
|
def hierarchy(result_set,depth = 0)
|
4
4
|
result_group = group_result_set(result_set)
|
5
|
-
(depth
|
5
|
+
level_check(depth) ? self.tree_structure(result_set,result_group) : self.tree_structure_depth(result_set,result_group,depth.to_i)
|
6
6
|
end
|
7
7
|
|
8
8
|
def tree_structure(result_set,result_group)
|
9
|
-
result_group[self.id]
|
9
|
+
presence_check(result_group[self.id]) ? self.attributes : self.attributes.merge({:children => result_group[self.id].map{|x| x.tree_structure(result_set,result_group)}})
|
10
10
|
end
|
11
11
|
|
12
12
|
def tree_structure_depth(result_set,result_group,depth,increment = 1)
|
13
|
-
result_group[self.id]
|
13
|
+
presence_check(result_group[self.id]) ? self.attributes : self.attributes.merge({:children => result_group[self.id].map{|x| x.tree_structure_depth(result_set,result_group,depth,increment + 1)}}) unless compare(increment,depth)
|
14
14
|
end
|
15
15
|
|
16
16
|
end
|
@@ -2,15 +2,33 @@ module HierarchyWithLevel
|
|
2
2
|
|
3
3
|
def hierarchy_level(result_set,depth = 0)
|
4
4
|
result_group = group_result_set(result_set)
|
5
|
-
(depth
|
5
|
+
level_check(depth) ? self.tree_structure_level(result_set,result_group) : self.tree_structure_depth_level(result_set,result_group,depth.to_i)
|
6
6
|
end
|
7
7
|
|
8
8
|
def tree_structure_level(result_set,result_group,increment = 1)
|
9
|
-
result_group[self.id]
|
9
|
+
presence_check(result_group[self.id]) ? self.attributes.merge({:level => increment}) : self.attributes.merge({:level => increment, :children => result_group[self.id].map{|x| x.tree_structure_level(result_set,result_group,increment + 1)}})
|
10
10
|
end
|
11
11
|
|
12
12
|
def tree_structure_depth_level(result_set,result_group,depth,increment = 1)
|
13
|
-
result_group[self.id]
|
13
|
+
presence_check(result_group[self.id]) ? self.attributes.merge({:level => increment}) : self.attributes.merge({:level => increment, :children => result_group[self.id].map{|x| x.tree_structure_depth_level(result_set,result_group,depth,increment + 1)}}) unless compare(increment,depth)
|
14
|
+
end
|
15
|
+
|
16
|
+
def hchildren(result_set)
|
17
|
+
result_group = group_result_set(result_set)
|
18
|
+
self.hchildren_structure(result_set,result_group)
|
19
|
+
end
|
20
|
+
|
21
|
+
def hchildren_ids(result_set)
|
22
|
+
result_group = group_result_set(result_set)
|
23
|
+
self.hchildren_structure_ids(result_set,result_group)
|
24
|
+
end
|
25
|
+
|
26
|
+
def hchildren_structure(result_set,result_group)
|
27
|
+
result_group[self.id] unless presence_check(result_group[self.id])
|
28
|
+
end
|
29
|
+
|
30
|
+
def hchildren_structure_ids(result_set,result_group)
|
31
|
+
result_group[self.id].map(&:id) unless presence_check(result_group[self.id])
|
14
32
|
end
|
15
33
|
|
16
34
|
end
|
metadata
CHANGED
@@ -1,17 +1,17 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tree_hierarchy
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 2.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
|
-
-
|
7
|
+
- Dheenadhayalan
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-04-
|
11
|
+
date: 2014-04-15 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: " \n Tree_hierarchy allows to form a tree structure based on parent-child
|
14
|
-
relationship \n with simple and fast computation
|
14
|
+
relationship \n with simple and fast computation for large records. Additional
|
15
15
|
feature of updating\n the parent record with the sum of its child value\n \n"
|
16
16
|
email: dheenaindian@gmail.com
|
17
17
|
executables: []
|
@@ -27,7 +27,7 @@ homepage: https://github.com/dheenaINDIAN/tree_hierarchy.git
|
|
27
27
|
licenses:
|
28
28
|
- MIT
|
29
29
|
metadata: {}
|
30
|
-
post_install_message: Thanks for installing!
|
30
|
+
post_install_message: Thanks for installing Tree_hierarchy!
|
31
31
|
rdoc_options: []
|
32
32
|
require_paths:
|
33
33
|
- lib
|