Module: IOSParser::IOS::Queryable::Matcher
- Defined in:
- lib/ios_parser/ios/queryable.rb
Overview
module MatcherReader
Class Method Summary collapse
- ._depth(max, command) ⇒ Object
- .all(expressions, command) ⇒ Object
- .any(expressions, command) ⇒ Object
- .any_child(expr, command) ⇒ Object
- .compare_string_or_case(a_object, b_object) ⇒ Object
- .contains(req_ary, command) ⇒ Object
- .depth(expr, command) ⇒ Object
- .depth_exact(expr, command) ⇒ Object
- .depth_range(expr, command) ⇒ Object
- .ends_with(req_ary, command) ⇒ Object
- .line(expr, command) ⇒ Object
- .name(expr, command) ⇒ Object
- .no_child(expr, command) ⇒ Object
- .none(expressions, command) ⇒ Object
- .not_all(expressions, command) ⇒ Object (also: not)
- .parent(expr, command) ⇒ Object
- .procedure(expr, command) ⇒ Object
- .starts_with(req_ary, command) ⇒ Object
Class Method Details
._depth(max, command) ⇒ Object
205 206 207 208 209 210 211 212 213 214 |
# File 'lib/ios_parser/ios/queryable.rb', line 205 def _depth(max, command) level = 0 ptr = command while ptr.parent ptr = ptr.parent level += 1 return Float::MIN if level > max end level end |
.all(expressions, command) ⇒ Object
173 174 175 176 177 178 179 |
# File 'lib/ios_parser/ios/queryable.rb', line 173 def all(expressions, command) expressions.all? do |expr| expr.each_pair.all? do |pred, arg| send(pred, arg, command) end end end |
.any(expressions, command) ⇒ Object
165 166 167 168 169 170 171 |
# File 'lib/ios_parser/ios/queryable.rb', line 165 def any(expressions, command) expressions.any? do |expr| expr.each_pair.any? do |pred, arg| send(pred, arg, command) end end end |
.any_child(expr, command) ⇒ Object
157 158 159 |
# File 'lib/ios_parser/ios/queryable.rb', line 157 def any_child(expr, command) command.find(expr) end |
.compare_string_or_case(a_object, b_object) ⇒ Object
134 135 136 137 138 139 140 141 |
# File 'lib/ios_parser/ios/queryable.rb', line 134 def compare_string_or_case(a_object, b_object) case a_object when String a_object == b_object.to_s else a_object === b_object end end |
.contains(req_ary, command) ⇒ Object
120 121 122 123 124 125 126 |
# File 'lib/ios_parser/ios/queryable.rb', line 120 def contains(req_ary, command) (0..command.args.length - req_ary.length).any? do |j| (0..req_ary.length - 1).all? do |i| compare_string_or_case(req_ary[i], command.args[i + j]) end end end |
.depth(expr, command) ⇒ Object
190 191 192 193 194 195 |
# File 'lib/ios_parser/ios/queryable.rb', line 190 def depth(expr, command) case expr when Integer then depth_exact(expr, command) when Range then depth_range(expr, command) end end |
.depth_exact(expr, command) ⇒ Object
197 198 199 |
# File 'lib/ios_parser/ios/queryable.rb', line 197 def depth_exact(expr, command) _depth(expr, command) == expr end |
.depth_range(expr, command) ⇒ Object
201 202 203 |
# File 'lib/ios_parser/ios/queryable.rb', line 201 def depth_range(expr, command) _depth(expr.last, command) > expr.first end |
.ends_with(req_ary, command) ⇒ Object
128 129 130 131 132 |
# File 'lib/ios_parser/ios/queryable.rb', line 128 def ends_with(req_ary, command) (1..req_ary.length).all? do |i| compare_string_or_case(req_ary[-i], command.args[-1]) end end |
.line(expr, command) ⇒ Object
147 148 149 |
# File 'lib/ios_parser/ios/queryable.rb', line 147 def line(expr, command) expr === command.line end |
.name(expr, command) ⇒ Object
110 111 112 |
# File 'lib/ios_parser/ios/queryable.rb', line 110 def name(expr, command) expr === command.name end |
.no_child(expr, command) ⇒ Object
161 162 163 |
# File 'lib/ios_parser/ios/queryable.rb', line 161 def no_child(expr, command) !command.find(expr) end |
.none(expressions, command) ⇒ Object
186 187 188 |
# File 'lib/ios_parser/ios/queryable.rb', line 186 def none(expressions, command) expressions.none? { |expr| all([expr], command) } end |
.not_all(expressions, command) ⇒ Object Also known as: not
181 182 183 |
# File 'lib/ios_parser/ios/queryable.rb', line 181 def not_all(expressions, command) !expressions.all? { |expr| all([expr], command) } end |
.parent(expr, command) ⇒ Object
151 152 153 154 155 |
# File 'lib/ios_parser/ios/queryable.rb', line 151 def parent(expr, command) expr.each_pair.all? do |pred, arg| command.parent && send(pred, arg, command.parent) end end |
.procedure(expr, command) ⇒ Object
143 144 145 |
# File 'lib/ios_parser/ios/queryable.rb', line 143 def procedure(expr, command) expr.call(command) end |
.starts_with(req_ary, command) ⇒ Object
114 115 116 117 118 |
# File 'lib/ios_parser/ios/queryable.rb', line 114 def starts_with(req_ary, command) (0..req_ary.length - 1).all? do |i| compare_string_or_case(req_ary[i], command.args[i]) end end |