Class: GitSu::UserList
- Inherits:
-
Object
- Object
- GitSu::UserList
- Defined in:
- lib/gitsu/user_list.rb
Defined Under Namespace
Classes: Search
Constant Summary collapse
- MATCH_STRATEGIES =
[ # Whole word of name lambda { |search_term, user| user.name =~ /\b#{search_term}\b/i }, # Beginning of word in name lambda { |search_term, user| user.name =~ /\b#{search_term}/i }, # Initials lambda { |search_term, user| user.initials =~ /#{search_term}/i }, # Segment anywhere in name or email lambda do |search_term, user| "#{user.name} #{user.email}" =~ /#{search_term}/i end ]
Instance Method Summary collapse
- #add(user) ⇒ Object
- #find(*search_terms) ⇒ Object
-
#initialize(user_file) ⇒ UserList
constructor
A new instance of UserList.
- #list ⇒ Object
Constructor Details
#initialize(user_file) ⇒ UserList
Returns a new instance of UserList.
35 36 37 |
# File 'lib/gitsu/user_list.rb', line 35 def initialize(user_file) @user_file = user_file end |
Instance Method Details
#add(user) ⇒ Object
39 40 41 |
# File 'lib/gitsu/user_list.rb', line 39 def add(user) @user_file.write(user) end |
#find(*search_terms) ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/gitsu/user_list.rb', line 47 def find(*search_terms) all_users = list searches = all_matching_users(all_users, search_terms) searches.each do |search| if search.matches.empty? raise "No user found matching '#{search.term}'" end end find_unique_combination(searches) or raise "Couldn't find a combination of users matching #{search_terms.quote.to_sentence}" end |
#list ⇒ Object
43 44 45 |
# File 'lib/gitsu/user_list.rb', line 43 def list @user_file.read end |