Class: Babosa::Candidates

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

Overview

This iterates through slug candidates and generates them lazily. In other words, if the first candidate succeeds, the remaning ones are not evaluated. It also appends a fallback candidate which uses the final candidate’s slug plus a GUID.

Instance Method Summary collapse

Constructor Details

#initialize(object, *array) ⇒ Candidates



13
14
15
16
# File 'lib/babosa/candidates.rb', line 13

def initialize(object, *array)
  @candidates = to_candidate_array(object, array.flatten(1))
  @candidates << (@candidates.last.dup << -> {SecureRandom.uuid})
end

Instance Method Details

#each(*args, &block) ⇒ Object



18
19
20
21
22
# File 'lib/babosa/candidates.rb', line 18

def each(*args, &block)
  @candidates.each(*args) do |candidate|
    yield candidate.map(&:call).join(' ').to_slug.normalize!
  end
end