Class: SystemNavigation::ExpressionTree
- Inherits:
-
Object
- Object
- SystemNavigation::ExpressionTree
- Defined in:
- lib/system_navigation/expression_tree.rb
Overview
Class Method Summary collapse
Instance Method Summary collapse
- #includes?(obj) ⇒ Boolean
-
#initialize(method: nil, source: nil) ⇒ ExpressionTree
constructor
A new instance of ExpressionTree.
- #parse ⇒ Object
Constructor Details
#initialize(method: nil, source: nil) ⇒ ExpressionTree
Returns a new instance of ExpressionTree.
9 10 11 12 13 14 15 16 17 |
# File 'lib/system_navigation/expression_tree.rb', line 9 def initialize(method: nil, source: nil) @method = method @source = source @keywords = [] @hashes = [] @arrays = [] @ranges = [] @tree = nil end |
Class Method Details
.of(method:, source:) ⇒ Object
3 4 5 6 7 |
# File 'lib/system_navigation/expression_tree.rb', line 3 def self.of(method:, source:) tree = self.new(method: method, source: source) tree.parse tree end |
Instance Method Details
#includes?(obj) ⇒ Boolean
35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/system_navigation/expression_tree.rb', line 35 def includes?(obj) built = Ripper.sexp(obj.inspect) built_obj = built[1][0][1] collection = case obj when Array then @arrays when Hash then @hashes when Range then @ranges else [] end !!find_includes(collection, built_obj) || @keywords.include?(obj.inspect) end |
#parse ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/system_navigation/expression_tree.rb', line 19 def parse return false if [@method, @source].compact.empty? @tree = Ripper.sexp(@source) return false unless @tree parsed = @tree[1][0] return false unless parsed.first == :def method_body_tree = parsed[3][1] self.walk(method_body_tree) true end |