Class: Mj::AlternativeFile::Candidates

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/mj/alternative_file/candidates.rb

Instance Method Summary collapse

Constructor Details

#initialize(candidates = []) ⇒ Candidates

Returns a new instance of Candidates.



8
9
10
# File 'lib/mj/alternative_file/candidates.rb', line 8

def initialize(candidates = [])
  @items = candidates.dup
end

Instance Method Details

#add(candidate) ⇒ Object



16
17
18
# File 'lib/mj/alternative_file/candidates.rb', line 16

def add(candidate)
  @items.push(candidate)
end

#after(reference_file) ⇒ Object



36
37
38
# File 'lib/mj/alternative_file/candidates.rb', line 36

def after(reference_file)
  next_file(@items, reference_file)
end

#before(reference_file) ⇒ Object



40
41
42
# File 'lib/mj/alternative_file/candidates.rb', line 40

def before(reference_file)
  next_file(@items.reverse, reference_file)
end

#each(&block) ⇒ Object



12
13
14
# File 'lib/mj/alternative_file/candidates.rb', line 12

def each(&block)
  @items.each(&block)
end

#existingObject



24
25
26
# File 'lib/mj/alternative_file/candidates.rb', line 24

def existing
  select(&:exist?)
end

#of_types(types) ⇒ Object



20
21
22
# File 'lib/mj/alternative_file/candidates.rb', line 20

def of_types(types)
  select { |item| types.include?(item.type) }
end

#select(&block) ⇒ Object



32
33
34
# File 'lib/mj/alternative_file/candidates.rb', line 32

def select(&block)
  new(@items.select(&block))
end

#sorted_by_pathObject



44
45
46
# File 'lib/mj/alternative_file/candidates.rb', line 44

def sorted_by_path
  new(@items.sort_by(&:path))
end

#uniqueObject



28
29
30
# File 'lib/mj/alternative_file/candidates.rb', line 28

def unique
  new(@items.uniq(&:path))
end