Class: BEL::Completion::MatchFunctionRule

Inherits:
Object
  • Object
show all
Includes:
Rule
Defined in:
lib/bel/completion_rule.rb

Overview

MatchFunctionRule defines a function completion rule. This rule relies on a BELParser::Language::Specification for the available functions.

Instance Method Summary collapse

Methods included from Rule

#apply

Instance Method Details

#_apply(token_list, active_token, active_token_index, options = {}) ⇒ Object



109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
# File 'lib/bel/completion_rule.rb', line 109

def _apply(token_list, active_token, active_token_index, options = {})
  if token_list.empty? or active_token.type == :O_PAREN
    return spec_functions(options[:specification]).map(&method(:map_function))
  end

  if active_token.type == :IDENT
    value   = active_token.value.downcase
    matches = spec_functions(options[:specification]).select do |func|
      func.short.to_s.include?(value) || func.long.to_s.include?(value)
    end
    return matches.map(&method(:map_function))
  end

  return EMPTY_MATCH
end