Sha256: 937fc8ca924fbf2de64da7571bd61da324889c00dc0387e5ddaa359544fc21fd

Contents?: true

Size: 559 Bytes

Versions: 1

Compression:

Stored size: 559 Bytes

Contents

require 'graphed_fuzzy_search'

module Mayu
  class UserCompleter
    def initialize(users)
      @cache_key = cache_key_for(users)
      @collection = GraphedFuzzySearch.new(users, attributes: %i(name aliases))
    end

    attr_reader :collection

    def query(str)
      collection.query(str)
    end

    def update(users)
      if @cache_key == cache_key_for(users)
        self
      else
        self.class.new(users)
      end
    end

    private
    
    def cache_key_for(users)
      users.map{ |_| [_.name, _.aliases, _.key] }
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
mayu-0.1.0.beta1 lib/mayu/user_completer.rb