Class: Babosa::Generator
- Inherits:
-
Object
- Object
- Babosa::Generator
- Defined in:
- lib/babosa/generator.rb
Overview
A simple slug generator using a Set as a backend. Obviously this is silly and potentially a great way to leak memory, but it demonstrates the funcionality.
Instance Method Summary collapse
- #add(slug) ⇒ Object
- #available?(slug) ⇒ Boolean
- #generate(candidates) ⇒ Object
-
#initialize ⇒ Generator
constructor
A new instance of Generator.
Constructor Details
#initialize ⇒ Generator
Returns a new instance of Generator.
8 9 10 |
# File 'lib/babosa/generator.rb', line 8 def initialize @set = Set.new end |
Instance Method Details
#add(slug) ⇒ Object
16 17 18 |
# File 'lib/babosa/generator.rb', line 16 def add(slug) @set.add slug; slug end |
#available?(slug) ⇒ Boolean
12 13 14 |
# File 'lib/babosa/generator.rb', line 12 def available?(slug) !@set.member?(slug) end |
#generate(candidates) ⇒ Object
20 21 22 |
# File 'lib/babosa/generator.rb', line 20 def generate(candidates) candidates.each {|c| return add c if available?(c)} end |