Class: BELParser::Completion::RelationshipCompleter

Inherits:
BaseCompleter
  • Object
show all
Defined in:
lib/bel_parser/completion.rb

Direct Known Subclasses

AllRelationshipCompleter

Instance Method Summary collapse

Methods inherited from BaseCompleter

#initialize

Methods included from Parsers::AST::Sexp

#annotation_definition, #argument, #blank_line, build, #comment, #comment_line, #document_property, #domain, #function, #identifier, #keyword, #list, #list_item, #multi_identifier, #name, #namespace_definition, #nested_statement, #object, #observed_term, #parameter, #pattern, #prefix, #relationship, #set, #simple_statement, #statement, #string, #subject, #term, #unset, #uri, #url, #value

Constructor Details

This class inherits a constructor from BELParser::Completion::BaseCompleter

Instance Method Details

#complete(string_literal, caret_position) ⇒ Object



905
906
907
908
909
910
911
912
913
914
# File 'lib/bel_parser/completion.rb', line 905

def complete(string_literal, caret_position)
  @spec.relationships
    .select  { |relationship|
      relationship =~ /.*#{Regexp.quote(string_literal)}.*/i
    }
    .sort_by { |relationship| relationship.long }
    .map     { |relationship|
      make_completion(relationship)
    }
end

#make_completion(relationship) ⇒ Object



916
917
918
919
920
921
922
923
# File 'lib/bel_parser/completion.rb', line 916

def make_completion(relationship)
  short = relationship.short.to_s
  [
    relationship,
    relationship(
      short)
  ]
end