Module: IOSParser::IOS::Queryable::MatcherReader

Defined in:
lib/ios_parser/ios/queryable.rb

Class Method Summary collapse

Class Method Details

.array_wrap_and_map(expr) ⇒ Object Also known as: any, all, none, not, not_all



87
88
89
90
# File 'lib/ios_parser/ios/queryable.rb', line 87

def array_wrap_and_map(expr)
  (expr.respond_to?(:map) && !expr.is_a?(Hash) ? expr : [expr])
    .map { |e| query_expression(e) }
end

.depth(expr) ⇒ Object



97
98
99
100
101
102
103
104
# File 'lib/ios_parser/ios/queryable.rb', line 97

def depth(expr)
  unless expr.is_a?(Integer) || (expr.is_a?(Range) &&
                                 expr.first.is_a?(Integer) &&
                                 expr.last.is_a?(Integer))
    raise("Invalid depth constraint in query: #{expr}")
  end
  expr
end

.line(expr) ⇒ Object



79
80
81
82
83
84
85
# File 'lib/ios_parser/ios/queryable.rb', line 79

def line(expr)
  case expr
  when String, Regexp then expr
  when Array          then expr.join(' ')
  else raise("Invalid line condition in query: #{expr}")
  end
end

.name(expr) ⇒ Object



58
59
60
# File 'lib/ios_parser/ios/queryable.rb', line 58

def name(expr)
  expr
end

.procedure(expr) ⇒ Object



72
73
74
75
76
77
# File 'lib/ios_parser/ios/queryable.rb', line 72

def procedure(expr)
  unless expr.respond_to?(:call)
    raise("Invalid procedure in query: #{expr}")
  end
  expr
end

.query_expression(raw) ⇒ Object Also known as: parent, any_child, no_child



39
40
41
42
43
44
45
46
47
# File 'lib/ios_parser/ios/queryable.rb', line 39

def query_expression(raw)
  case raw
  when Hash          then query_expression_hash(raw)
  when Proc          then { procedure: procedure(raw) }
  when Regexp        then { line: line(raw) }
  when String, Array then { starts_with: starts_with(raw) }
  else raise("Invalid query: #{raw.inspect}")
  end
end

.query_expression_hash(original) ⇒ Object



52
53
54
55
56
# File 'lib/ios_parser/ios/queryable.rb', line 52

def query_expression_hash(original)
  raw = original.dup
  raw.each_pair { |pred, arg| raw[pred] &&= send(pred, arg) }
  raw
end

.starts_with(expr) ⇒ Object Also known as: contains, ends_with



62
63
64
65
66
67
68
# File 'lib/ios_parser/ios/queryable.rb', line 62

def starts_with(expr)
  case expr
  when String then expr.split
  when Array  then expr
  else raise("Invalid #{__method__} condition in query: #{expr}")
  end
end