pebbles-uid 0.0.11 → 0.0.12
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/pebbles-uid/class_methods.rb +4 -0
- data/lib/pebbles-uid/labels.rb +11 -0
- data/lib/pebbles-uid/roots.rb +21 -8
- data/lib/pebbles-uid/version.rb +1 -1
- data/spec/labels_spec.rb +15 -4
- data/spec/roots_spec.rb +21 -9
- metadata +4 -4
data/lib/pebbles-uid/labels.rb
CHANGED
@@ -25,6 +25,7 @@ module Pebbles
|
|
25
25
|
end
|
26
26
|
|
27
27
|
def parent_of?(other)
|
28
|
+
return false if values == other.values
|
28
29
|
parent = true
|
29
30
|
values.each_with_index do |value, i|
|
30
31
|
parent = false unless value == other.values[i]
|
@@ -32,6 +33,16 @@ module Pebbles
|
|
32
33
|
parent
|
33
34
|
end
|
34
35
|
|
36
|
+
def child_of?(other)
|
37
|
+
child = true
|
38
|
+
other.values.each_with_index do |label, i|
|
39
|
+
if label != values[i]
|
40
|
+
child = false
|
41
|
+
end
|
42
|
+
end
|
43
|
+
child && other.size != size
|
44
|
+
end
|
45
|
+
|
35
46
|
def ambiguous?
|
36
47
|
value == '*' || values.empty? || wildcard?
|
37
48
|
end
|
data/lib/pebbles-uid/roots.rb
CHANGED
@@ -1,14 +1,27 @@
|
|
1
1
|
module Pebbles
|
2
2
|
class Uid
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
3
|
+
class Roots
|
4
|
+
|
5
|
+
attr_reader :paths
|
6
|
+
def initialize(uids)
|
7
|
+
@paths = {}
|
8
|
+
uids.each { |uid|
|
9
|
+
@paths[uid] = Labels.new(Pebbles::Uid.path(uid))
|
9
10
|
}
|
10
|
-
|
11
|
-
|
11
|
+
end
|
12
|
+
|
13
|
+
def unique
|
14
|
+
unless @unique
|
15
|
+
@unique = []
|
16
|
+
paths.each do |uid, path|
|
17
|
+
unless paths.any? { |_, other| path.child_of?(other) }
|
18
|
+
@unique << uid
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
@unique
|
23
|
+
end
|
24
|
+
|
12
25
|
end
|
13
26
|
end
|
14
27
|
end
|
data/lib/pebbles-uid/version.rb
CHANGED
data/spec/labels_spec.rb
CHANGED
@@ -49,10 +49,21 @@ describe Pebbles::Uid::Labels do
|
|
49
49
|
let(:a_b_c) { Pebbles::Uid::Labels.new('a.b.c') }
|
50
50
|
let(:a_b_d) { Pebbles::Uid::Labels.new('a.b.d') }
|
51
51
|
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
52
|
+
specify { a.parent_of?(a).should == false }
|
53
|
+
specify { a_b_c.parent_of?(a).should == false }
|
54
|
+
specify { a.parent_of?(a_b_c).should == true }
|
55
|
+
specify { a_b_c.parent_of?(a_b_d).should == false }
|
56
|
+
end
|
57
|
+
|
58
|
+
context "#child_of?" do
|
59
|
+
let(:a) { Pebbles::Uid::Labels.new('a') }
|
60
|
+
let(:b) { Pebbles::Uid::Labels.new('b') }
|
61
|
+
let(:a_b) { Pebbles::Uid::Labels.new('a.b') }
|
62
|
+
|
63
|
+
specify { a.child_of?(a).should == false }
|
64
|
+
specify { a_b.child_of?(a).should == true }
|
65
|
+
specify { a.child_of?(b).should == false }
|
66
|
+
specify { a.child_of?(a_b).should == false }
|
56
67
|
end
|
57
68
|
|
58
69
|
end
|
data/spec/roots_spec.rb
CHANGED
@@ -1,21 +1,33 @@
|
|
1
1
|
require 'pebbles-uid'
|
2
2
|
|
3
|
-
describe Pebbles::Uid do
|
3
|
+
describe Pebbles::Uid::Roots do
|
4
4
|
|
5
|
-
specify "
|
6
|
-
Pebbles::Uid.
|
5
|
+
specify "empty list is empty :)" do
|
6
|
+
Pebbles::Uid::Roots.new([]).unique.should eq([])
|
7
7
|
end
|
8
8
|
|
9
|
-
specify "
|
10
|
-
Pebbles::Uid.
|
9
|
+
specify "with one, has a single root" do
|
10
|
+
Pebbles::Uid::Roots.new(['boy:a$1']).unique.should eq(['boy:a$1'])
|
11
11
|
end
|
12
12
|
|
13
|
-
specify "
|
14
|
-
Pebbles::Uid.
|
13
|
+
specify "does not keep duplicates" do
|
14
|
+
Pebbles::Uid::Roots.new(['girl:a$1', 'girl:a$1']).unique.should eq(['girl:a$1'])
|
15
15
|
end
|
16
16
|
|
17
|
-
specify "
|
18
|
-
Pebbles::Uid.
|
17
|
+
specify "with two, returns just the parent" do
|
18
|
+
Pebbles::Uid::Roots.new(['kid:a$1', 'kid:a.b$2']).unique.should eq(['kid:a$1'])
|
19
|
+
end
|
20
|
+
|
21
|
+
specify "with two, returns just the parent, regardless of sort order" do
|
22
|
+
Pebbles::Uid::Roots.new(['baby:a.b$1', 'baby:a$2']).unique.should eq(['baby:a$2'])
|
23
|
+
end
|
24
|
+
|
25
|
+
specify "with non-intersecting nodes, returns both" do
|
26
|
+
Pebbles::Uid::Roots.new(['goat:a.b$1', 'goat:a.c$2']).unique.should eq(['goat:a.b$1', 'goat:a.c$2'])
|
27
|
+
end
|
28
|
+
|
29
|
+
specify "with similar, but non-intersecting nodes, returns both" do
|
30
|
+
Pebbles::Uid::Roots.new(['pig:a.b.c$1', 'pig:a.c.d$2']).unique.should eq(['pig:a.b.c$1', 'pig:a.c.d$2'])
|
19
31
|
end
|
20
32
|
|
21
33
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pebbles-uid
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.12
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-11-
|
12
|
+
date: 2012-11-21 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rspec
|
16
|
-
requirement: &
|
16
|
+
requirement: &70359179077380 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,7 +21,7 @@ dependencies:
|
|
21
21
|
version: '0'
|
22
22
|
type: :development
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70359179077380
|
25
25
|
description: Handle pebble UIDs conveniently.
|
26
26
|
email:
|
27
27
|
- katrina.owen@gmail.com
|