Class: Contributions::RepositoryList

Inherits:
Object
  • Object
show all
Defined in:
lib/contributions/repository_list.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ RepositoryList

Returns a new instance of RepositoryList.



6
7
8
# File 'lib/contributions/repository_list.rb', line 6

def initialize(*args)
  @list = [args].flatten
end

Instance Attribute Details

#listObject (readonly)

Returns the value of attribute list.



4
5
6
# File 'lib/contributions/repository_list.rb', line 4

def list
  @list
end

Instance Method Details

#add(repos) ⇒ Object

Public: Add a string or array of strings to the repository list.

repos - a string or an array of strings (each of which is a

'username/repo')

Returns a RepositoryList



16
17
18
19
# File 'lib/contributions/repository_list.rb', line 16

def add(repos)
  @list.push(repos).flatten!
  self
end

#key_value_pairsObject

Public: Turn repositories into key value pairs.

Returns an Array of Hashes :repository



24
25
26
27
28
29
30
31
32
# File 'lib/contributions/repository_list.rb', line 24

def key_value_pairs
  results = []
  @list.each do |e|
    p = e.split('/')
    results.push Hash[:username => p[0], :repository => p[1]]
  end

  results
end

#only(repos) ⇒ Object

Public: Replace list of repositories with the list provided.

repos - a string or an array of strings (each of which is a

'username/repo')

Returns a RepositoryList



40
41
42
43
# File 'lib/contributions/repository_list.rb', line 40

def only(repos)
  @list = [repos].flatten
  self
end

#remove(repos) ⇒ Object

Public: Remove a string or array of strings from the repository list. repos - a string or an array of strings (each of which is a

'username/repo')

Returns a RepositoryList



51
52
53
54
# File 'lib/contributions/repository_list.rb', line 51

def remove(repos)
  @list.delete_if { |e| [repos].flatten.include? e }
  self
end