Class: EmployMe::Parser::ProgrammingLanguage::Strategies::PatternMatch
- Inherits:
-
Object
- Object
- EmployMe::Parser::ProgrammingLanguage::Strategies::PatternMatch
- Defined in:
- lib/employ_me/parser/programming_language/strategies/pattern_match.rb
Class Method Summary collapse
-
.perform(root_node) ⇒ Object
Return [programming language name].
Class Method Details
.perform(root_node) ⇒ Object
Return [programming language name]
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/employ_me/parser/programming_language/strategies/pattern_match.rb', line 7 def self.perform(root_node) tree = [root_node] # Depth First Search while tree.size > 0 curr_node = tree.shift if curr_node.children.all? { |child| child.name == "comment" || child.name == 'text' } curr_node_text = curr_node.text # C# regex = Regexp.new('C#', Regexp::IGNORECASE) return 'c_sharp' if regex.match(curr_node_text) # Go regex = Regexp.new('Go') return 'go' if regex.match(curr_node_text) # Java regex = Regexp.new('Java', Regexp::IGNORECASE) return 'java' if regex.match(curr_node_text) # Javascript regex = Regexp.new('Node', Regexp::IGNORECASE) return 'javascript' if regex.match(curr_node_text) regex = Regexp.new('React', Regexp::IGNORECASE) return 'javascript' if regex.match(curr_node_text) regex = Regexp.new('Typescript', Regexp::IGNORECASE) return 'javascript' if regex.match(curr_node_text) # Kotlin regex = Regexp.new('Kotlin', Regexp::IGNORECASE) return 'kotlin' if regex.match(curr_node_text) # Python regex = Regexp.new('Python', Regexp::IGNORECASE) return 'python' if regex.match(curr_node_text) # Ruby regex = Regexp.new('Ruby', Regexp::IGNORECASE) return 'ruby' if regex.match(curr_node_text) regex = Regexp.new('Ruby on Rails', Regexp::IGNORECASE) return 'ruby' if regex.match(curr_node_text) # Swift regex = Regexp.new('Swift', Regexp::IGNORECASE) return 'swift' if regex.match(curr_node_text) end tree.concat(curr_node.children) end nil end |