Class: Querly::Analyzer
- Inherits:
-
Object
- Object
- Querly::Analyzer
- Defined in:
- lib/querly/analyzer.rb
Instance Attribute Summary collapse
-
#rules ⇒ Object
readonly
Returns the value of attribute rules.
-
#scripts ⇒ Object
readonly
Returns the value of attribute scripts.
-
#taggings ⇒ Object
readonly
Returns the value of attribute taggings.
Instance Method Summary collapse
- #applicable_rule?(tagging, rule) ⇒ Boolean
- #each_subnode(node_pair) {|node_pair| ... } ⇒ Object
- #find(pattern) ⇒ Object
-
#initialize(taggings:) ⇒ Analyzer
constructor
A new instance of Analyzer.
-
#run ⇒ Object
yields(script, rule, node_pair).
- #test_pair(node_pair, pattern) ⇒ Object
Constructor Details
#initialize(taggings:) ⇒ Analyzer
Returns a new instance of Analyzer.
7 8 9 10 11 |
# File 'lib/querly/analyzer.rb', line 7 def initialize(taggings:) @rules = [] @scripts = [] @taggings = taggings end |
Instance Attribute Details
#rules ⇒ Object (readonly)
Returns the value of attribute rules.
3 4 5 |
# File 'lib/querly/analyzer.rb', line 3 def rules @rules end |
#scripts ⇒ Object (readonly)
Returns the value of attribute scripts.
4 5 6 |
# File 'lib/querly/analyzer.rb', line 4 def scripts @scripts end |
#taggings ⇒ Object (readonly)
Returns the value of attribute taggings.
5 6 7 |
# File 'lib/querly/analyzer.rb', line 5 def taggings @taggings end |
Instance Method Details
#applicable_rule?(tagging, rule) ⇒ Boolean
46 47 48 49 50 51 52 |
# File 'lib/querly/analyzer.rb', line 46 def applicable_rule?(tagging, rule) if tagging && !rule..empty? tagging..any? {|set| set.subset?(rule.) } else true end end |
#each_subnode(node_pair) {|node_pair| ... } ⇒ Object
54 55 56 57 58 59 60 61 62 |
# File 'lib/querly/analyzer.rb', line 54 def each_subnode(node_pair, &block) return unless node_pair.node yield node_pair node_pair.children.each do |child| each_subnode child, &block end end |
#find(pattern) ⇒ Object
32 33 34 35 36 37 38 39 40 |
# File 'lib/querly/analyzer.rb', line 32 def find(pattern) scripts.each do |script| each_subnode script.root_pair do |node_pair| if test_pair(node_pair, pattern) yield script, node_pair end end end end |
#run ⇒ Object
yields(script, rule, node_pair)
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/querly/analyzer.rb', line 16 def run scripts.each do |script| tagging = taggings.find {|tagging| tagging.applicable?(script) } each_subnode script.root_pair do |node_pair| rules.each do |rule| if applicable_rule?(tagging, rule) if rule.patterns.any? {|pattern| test_pair(node_pair, pattern) } yield script, rule, node_pair end end end end end end |
#test_pair(node_pair, pattern) ⇒ Object
42 43 44 |
# File 'lib/querly/analyzer.rb', line 42 def test_pair(node_pair, pattern) pattern.expr =~ node_pair && pattern.test_kind(node_pair) end |