Sha256: 6a8b8cd1b4fa71400ee7786cb20e029dcfe245bafff140b8b254f582c3c4b548

Contents?: true

Size: 674 Bytes

Versions: 1

Compression:

Stored size: 674 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.where("LOWER(first_name) LIKE ? AND LOWER(last_name) LIKE ?", name1, name2)
          .or(UcbRailsUser::User.where("LOWER(last_name) LIKE ? AND LOWER(first_name) LIKE ?", name1, name2))
      else
        UcbRailsUser::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

1 entries across 1 versions & 1 rubygems

Version Path
ucb_rails_user-5.0.0 app/models/ucb_rails_user/user_search.rb