ytools 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/VERSION +1 -1
- data/lib/ytools/path/selectors.rb +20 -22
- data/spec/path/executor_spec.rb +4 -0
- data/spec/path/selectors_spec.rb +11 -0
- data/spec/path/yamls/6.yml +7 -0
- metadata +4 -3
data/lib/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.2
|
@@ -85,23 +85,33 @@ module YTools::Path
|
|
85
85
|
@match = match
|
86
86
|
end
|
87
87
|
|
88
|
-
def select(
|
89
|
-
|
88
|
+
def select(element)
|
89
|
+
results = []
|
90
|
+
element_select(element, results)
|
91
|
+
if results.length == 1
|
92
|
+
results[0]
|
93
|
+
else
|
94
|
+
results
|
95
|
+
end
|
90
96
|
end
|
91
97
|
|
92
98
|
private
|
93
|
-
def
|
99
|
+
def element_select(element, results)
|
100
|
+
if element.is_a?(YTools::YamlObject)
|
101
|
+
hash_select(element, results)
|
102
|
+
elsif element.is_a?(Array)
|
103
|
+
element.each do |e|
|
104
|
+
element_select(e, results)
|
105
|
+
end
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
def hash_select(yaml, results)
|
94
110
|
yaml.yhash.each do |key, value|
|
95
111
|
if key == match
|
96
112
|
key_select(value, results)
|
97
113
|
end
|
98
|
-
|
99
|
-
end
|
100
|
-
|
101
|
-
if results.length == 1
|
102
|
-
results[0]
|
103
|
-
else
|
104
|
-
results
|
114
|
+
element_select(value, results)
|
105
115
|
end
|
106
116
|
end
|
107
117
|
|
@@ -116,17 +126,5 @@ module YTools::Path
|
|
116
126
|
results << value
|
117
127
|
end
|
118
128
|
end
|
119
|
-
|
120
|
-
def value_select(value, results)
|
121
|
-
if value.is_a?(YTools::YamlObject)
|
122
|
-
inner_select(value, results)
|
123
|
-
elsif value.is_a?(Array)
|
124
|
-
value.each do |v|
|
125
|
-
if v.is_a?(YTools::YamlObject)
|
126
|
-
inner_select(v, results)
|
127
|
-
end
|
128
|
-
end
|
129
|
-
end
|
130
|
-
end
|
131
129
|
end
|
132
130
|
end
|
data/spec/path/executor_spec.rb
CHANGED
@@ -41,5 +41,9 @@ module YTools::Path
|
|
41
41
|
it "should be able to pull out the keys for a hash" do
|
42
42
|
process('/a', '5.yml').should eql("b\nc\nd")
|
43
43
|
end
|
44
|
+
|
45
|
+
it "should be able to pull out a descendant selector with inner hashes" do
|
46
|
+
process('/a//b', '6.yml').should eql("c\nd\ne")
|
47
|
+
end
|
44
48
|
end
|
45
49
|
end
|
data/spec/path/selectors_spec.rb
CHANGED
@@ -119,5 +119,16 @@ module YTools::Path
|
|
119
119
|
found[0].should eql(2)
|
120
120
|
found[1].should eql('b')
|
121
121
|
end
|
122
|
+
|
123
|
+
it "should be able to pull out a list of subselectors" do
|
124
|
+
sel = ChildSelector.new('path')
|
125
|
+
sel.chain(DescendantSelector.new('subgroup'))
|
126
|
+
o = yo({'path' => [{'subgroup' => 'a', 'c' => 'd'}, {'subgroup' => 'b', 'c' => 'd'}]})
|
127
|
+
|
128
|
+
found = sel.select(o)
|
129
|
+
found.length.should eql(2)
|
130
|
+
found[0].should eql('a')
|
131
|
+
found[1].should eql('b')
|
132
|
+
end
|
122
133
|
end
|
123
134
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ytools
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 31
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 1
|
9
|
-
-
|
10
|
-
version: 0.1.
|
9
|
+
- 2
|
10
|
+
version: 0.1.2
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Gabe McArthur
|
@@ -75,6 +75,7 @@ files:
|
|
75
75
|
- spec/path/yamls/3.yml
|
76
76
|
- spec/path/yamls/4.yml
|
77
77
|
- spec/path/yamls/5.yml
|
78
|
+
- spec/path/yamls/6.yml
|
78
79
|
- spec/yaml_object_spec.rb
|
79
80
|
has_rdoc: true
|
80
81
|
homepage: http://github.com/gabemc/ytools
|