tukey 0.9.1RC → 1.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/tukey/data_set.rb +29 -9
- data/lib/tukey/version.rb +1 -1
- data/lib/tukey.rb +1 -0
- data/lib/vendor/hash.rb +59 -0
- metadata +5 -4
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: d8a8ef46adf65742612a80840d3efb68edc3e3c8
|
|
4
|
+
data.tar.gz: cbc2848c54ad1f31aea26470ef20ef96177f0f7c
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 2ac224235943f1e3cd63575bb1d0098cd6f86dee0d1f7e6fe2bfcfe41986d404a8fd28b8a11d751f6165adf757175d3aaa51a2098f5a7580b766334c03989c4c
|
|
7
|
+
data.tar.gz: 4a4bbaf6322b6382e09a880871be262e92e4b7dc4c6ce05ee0672e5b9f5690c0f3d9a3dabb9e1ee110cb0f13f07489aa65c3385d0ec5b9a992b3cf585792b5b6
|
data/lib/tukey/data_set.rb
CHANGED
|
@@ -121,17 +121,37 @@ class DataSet
|
|
|
121
121
|
end
|
|
122
122
|
end
|
|
123
123
|
|
|
124
|
-
def find(subtree_id)
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
124
|
+
def find(subtree_id = nil, &block)
|
|
125
|
+
return super if block_given?
|
|
126
|
+
return self if id == subtree_id
|
|
127
|
+
return nil unless data_array?
|
|
128
|
+
data.each do |child|
|
|
129
|
+
match = child.find(subtree_id)
|
|
130
|
+
return match if match
|
|
131
|
+
end
|
|
132
|
+
nil
|
|
133
|
+
end
|
|
134
|
+
|
|
135
|
+
def find_by(query)
|
|
136
|
+
return find { |s| s.to_comparable_h.deep_merge(query) == s.to_comparable_h }
|
|
137
|
+
end
|
|
132
138
|
|
|
133
|
-
|
|
139
|
+
def to_comparable_h
|
|
140
|
+
ch = {
|
|
141
|
+
id: self.id,
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
ch[:data] = data unless data_array?
|
|
145
|
+
|
|
146
|
+
if label
|
|
147
|
+
ch[:label] = {
|
|
148
|
+
id: label.id,
|
|
149
|
+
name: label.name,
|
|
150
|
+
meta: label.meta.to_h,
|
|
151
|
+
}
|
|
134
152
|
end
|
|
153
|
+
|
|
154
|
+
ch
|
|
135
155
|
end
|
|
136
156
|
|
|
137
157
|
def <=>(other)
|
data/lib/tukey/version.rb
CHANGED
data/lib/tukey.rb
CHANGED
data/lib/vendor/hash.rb
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
# Copyright (c) 2005-2014 David Heinemeier Hansson
|
|
2
|
+
|
|
3
|
+
# Permission is hereby granted, free of charge, to any person obtaining
|
|
4
|
+
# a copy of this software and associated documentation files (the
|
|
5
|
+
# "Software"), to deal in the Software without restriction, including
|
|
6
|
+
# without limitation the rights to use, copy, modify, merge, publish,
|
|
7
|
+
# distribute, sublicense, and/or sell copies of the Software, and to
|
|
8
|
+
# permit persons to whom the Software is furnished to do so, subject to
|
|
9
|
+
# the following conditions:
|
|
10
|
+
|
|
11
|
+
# The above copyright notice and this permission notice shall be
|
|
12
|
+
# included in all copies or substantial portions of the Software.
|
|
13
|
+
|
|
14
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
15
|
+
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
16
|
+
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
17
|
+
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
|
18
|
+
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
19
|
+
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
20
|
+
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
21
|
+
|
|
22
|
+
class Hash
|
|
23
|
+
# Returns a new hash with +self+ and +other_hash+ merged recursively.
|
|
24
|
+
#
|
|
25
|
+
# h1 = { a: true, b: { c: [1, 2, 3] } }
|
|
26
|
+
# h2 = { a: false, b: { x: [3, 4, 5] } }
|
|
27
|
+
#
|
|
28
|
+
# h1.deep_merge(h2) # => { a: false, b: { c: [1, 2, 3], x: [3, 4, 5] } }
|
|
29
|
+
#
|
|
30
|
+
# Like with Hash#merge in the standard library, a block can be provided
|
|
31
|
+
# to merge values:
|
|
32
|
+
#
|
|
33
|
+
# h1 = { a: 100, b: 200, c: { c1: 100 } }
|
|
34
|
+
# h2 = { b: 250, c: { c1: 200 } }
|
|
35
|
+
# h1.deep_merge(h2) { |key, this_val, other_val| this_val + other_val }
|
|
36
|
+
# # => { a: 100, b: 450, c: { c1: 300 } }
|
|
37
|
+
def deep_merge(other_hash, &block)
|
|
38
|
+
dup.deep_merge!(other_hash, &block)
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
# Same as +deep_merge+, but modifies +self+.
|
|
42
|
+
def deep_merge!(other_hash, &block)
|
|
43
|
+
other_hash.each_pair do |current_key, other_value|
|
|
44
|
+
this_value = self[current_key]
|
|
45
|
+
|
|
46
|
+
self[current_key] = if this_value.is_a?(Hash) && other_value.is_a?(Hash)
|
|
47
|
+
this_value.deep_merge(other_value, &block)
|
|
48
|
+
else
|
|
49
|
+
if block_given? && key?(current_key)
|
|
50
|
+
block.call(current_key, this_value, other_value)
|
|
51
|
+
else
|
|
52
|
+
other_value
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
self
|
|
58
|
+
end
|
|
59
|
+
end
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: tukey
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 1.0.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Achilleas Buisman
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: exe
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2017-01-
|
|
11
|
+
date: 2017-01-23 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: bundler
|
|
@@ -76,6 +76,7 @@ files:
|
|
|
76
76
|
- lib/tukey/data_set.rb
|
|
77
77
|
- lib/tukey/data_set/label.rb
|
|
78
78
|
- lib/tukey/version.rb
|
|
79
|
+
- lib/vendor/hash.rb
|
|
79
80
|
- tukey.gemspec
|
|
80
81
|
homepage: https://github.com/abuisman/tukey
|
|
81
82
|
licenses:
|
|
@@ -92,9 +93,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
92
93
|
version: '0'
|
|
93
94
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
94
95
|
requirements:
|
|
95
|
-
- - "
|
|
96
|
+
- - ">="
|
|
96
97
|
- !ruby/object:Gem::Version
|
|
97
|
-
version:
|
|
98
|
+
version: '0'
|
|
98
99
|
requirements: []
|
|
99
100
|
rubyforge_project:
|
|
100
101
|
rubygems_version: 2.5.1
|