Class: Git::Duo::AuthorCollection

Inherits:
Object
  • Object
show all
Defined in:
lib/git/duo/author_collection.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(authors) ⇒ AuthorCollection

Returns a new instance of AuthorCollection.



6
7
8
# File 'lib/git/duo/author_collection.rb', line 6

def initialize authors
  @authors = authors
end

Instance Attribute Details

#authorsObject (readonly)

Returns the value of attribute authors.



4
5
6
# File 'lib/git/duo/author_collection.rb', line 4

def authors
  @authors
end

Instance Method Details

#where(opts = {}) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/git/duo/author_collection.rb', line 10

def where opts = {}
  result = []
  result += opts.
    select {|k, _| authors.sample.respond_to? k }.
    map {|k, v|
      authors.
        sort_by(&:key).
        select {|o| o.send(k) =~ /#{v}/i }
    }.flatten
rescue NoMethodError
  result
end