Sha256: bf9d0fc37a257b7e461c5d8804255b97c121c330307d2c685e2846b81a433708

Contents?: true

Size: 632 Bytes

Versions: 14

Compression:

Stored size: 632 Bytes

Contents

module UcbRailsUser::UserSearch

  def self.find_users_by_name(name)
    return [] unless name.present?
    (name1, name2) = name
      .downcase
      .split
      .take(2)
      .reject { |n| n.blank? }
      .map { |n| "#{n}%" }
    query =
      if name1.present? && name2.present?
        User.where("LOWER(first_name) LIKE ? AND LOWER(last_name) LIKE ?", name1, name2)
          .or(User.where("LOWER(last_name) LIKE ? AND LOWER(first_name) LIKE ?", name1, name2))
      else
        User.where("LOWER(first_name) LIKE ? OR LOWER(last_name) LIKE ?", name1, name1)
      end
    query.order(:last_name, :first_name)
  end

end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
ucb_rails_user-4.1.2 app/models/ucb_rails_user/user_search.rb
ucb_rails_user-4.1.1 app/models/ucb_rails_user/user_search.rb
ucb_rails_user-4.1.0 app/models/ucb_rails_user/user_search.rb
ucb_rails_user-4.0.7 app/models/ucb_rails_user/user_search.rb
ucb_rails_user-4.0.6 app/models/ucb_rails_user/user_search.rb
ucb_rails_user-4.0.5 app/models/ucb_rails_user/user_search.rb
ucb_rails_user-4.0.4 app/models/ucb_rails_user/user_search.rb
ucb_rails_user-4.0.3 app/models/ucb_rails_user/user_search.rb
ucb_rails_user-4.0.2 app/models/ucb_rails_user/user_search.rb
ucb_rails_user-4.0.1 app/models/ucb_rails_user/user_search.rb
ucb_rails_user-4.0.0 app/models/ucb_rails_user/user_search.rb
ucb_rails_user-3.0.2 app/models/ucb_rails_user/user_search.rb
ucb_rails_user-4.0.0.beta1 app/models/ucb_rails_user/user_search.rb
ucb_rails_user-3.0.1 app/models/ucb_rails_user/user_search.rb