Module: IOSParser::IOS::Queryable

Included in:
Command, Document
Defined in:
lib/ios_parser/ios/queryable.rb

Defined Under Namespace

Modules: Matcher, MatcherReader

Instance Method Summary collapse

Instance Method Details

#_find(expr, &blk) ⇒ Object



29
30
31
32
33
34
35
# File 'lib/ios_parser/ios/queryable.rb', line 29

def _find(expr, &blk)
  _find_all(expr) do |command|
    yield(command) if blk
    return command
  end
  nil
end

#_find_all(expr, &blk) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/ios_parser/ios/queryable.rb', line 12

def _find_all(expr, &blk)
  [].tap do |ret|
    commands.each do |command|
      if match_expr(expr, command)
        ret << command
        yield(command) if blk
      end

      ret.push(*command._find_all(expr, &blk))
    end
  end
end

#find(expr, &blk) ⇒ Object



8
9
10
# File 'lib/ios_parser/ios/queryable.rb', line 8

def find(expr, &blk)
  _find(MatcherReader.query_expression(expr), &blk)
end

#find_all(expr, &blk) ⇒ Object



4
5
6
# File 'lib/ios_parser/ios/queryable.rb', line 4

def find_all(expr, &blk)
  _find_all(MatcherReader.query_expression(expr), &blk)
end

#match_expr(expr, command) ⇒ Object



25
26
27
# File 'lib/ios_parser/ios/queryable.rb', line 25

def match_expr(expr, command)
  expr.each_pair.all? { |pred, arg| Matcher.send(pred, arg, command) }
end