Sha256: cb3fa03d9d1343924b8fda2dc1497410b194a205210fa7f115ae51de1c1a8352

Contents?: true

Size: 689 Bytes

Versions: 6

Compression:

Stored size: 689 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?
        UcbRailsUser.user_class.where("LOWER(first_name) LIKE ? AND LOWER(last_name) LIKE ?", name1, name2)
          .or(UcbRailsUser.user_class.where("LOWER(last_name) LIKE ? AND LOWER(first_name) LIKE ?", name1, name2))
      else
        UcbRailsUser.user_class.where("LOWER(first_name) LIKE ? OR LOWER(last_name) LIKE ?", name1, name1)
      end
    query.order(:last_name, :first_name)
  end

end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
ucb_rails_user-7.0.0 app/models/ucb_rails_user/user_search.rb
ucb_rails_user-6.2.2 app/models/ucb_rails_user/user_search.rb
ucb_rails_user-6.2.0 app/models/ucb_rails_user/user_search.rb
ucb_rails_user-6.1.1 app/models/ucb_rails_user/user_search.rb
ucb_rails_user-6.1.0 app/models/ucb_rails_user/user_search.rb
ucb_rails_user-6.0.0 app/models/ucb_rails_user/user_search.rb