Class: AgnosticSlugs::Slug
- Inherits:
-
Object
- Object
- AgnosticSlugs::Slug
- Defined in:
- lib/agnostic_slugs/slug.rb
Instance Attribute Summary collapse
-
#counter ⇒ Object
readonly
Returns the value of attribute counter.
-
#original ⇒ Object
readonly
Returns the value of attribute original.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(original, counter = 1) ⇒ Slug
constructor
A new instance of Slug.
- #next ⇒ Object
- #step ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(original, counter = 1) ⇒ Slug
Returns a new instance of Slug.
9 10 11 12 |
# File 'lib/agnostic_slugs/slug.rb', line 9 def initialize(original, counter = 1) @original = original @counter = counter end |
Instance Attribute Details
#counter ⇒ Object (readonly)
Returns the value of attribute counter.
3 4 5 |
# File 'lib/agnostic_slugs/slug.rb', line 3 def counter @counter end |
#original ⇒ Object (readonly)
Returns the value of attribute original.
3 4 5 |
# File 'lib/agnostic_slugs/slug.rb', line 3 def original @original end |
Class Method Details
.step(name, &block) ⇒ Object
5 6 7 |
# File 'lib/agnostic_slugs/slug.rb', line 5 def self.step(name, &block) new(name).step(&block) end |
Instance Method Details
#next ⇒ Object
14 15 16 |
# File 'lib/agnostic_slugs/slug.rb', line 14 def next self.class.new(original, counter + 1) end |
#step ⇒ Object
18 19 20 21 22 23 24 25 |
# File 'lib/agnostic_slugs/slug.rb', line 18 def step instance = self loop do break if yield(instance.to_s) instance = instance.next end instance.to_s end |
#to_s ⇒ Object
27 28 29 |
# File 'lib/agnostic_slugs/slug.rb', line 27 def to_s @slug ||= generate end |