Class: SitemapGenerator::SitemapNamer
- Inherits:
-
Object
- Object
- SitemapGenerator::SitemapNamer
- Defined in:
- lib/sitemap_generator/sitemap_namer.rb
Overview
A class for generating sitemap names given the base for the filename. Deprecated. Rather use the SitemapGenerator::SimpleNamer
class and the namer
option on your sitemap object.
Example
namer = SitemapNamer.new(:sitemap) namer.to_s => ‘sitemap1.xml.gz’ namer.next.to_s => ‘sitemap2.xml.gz’
Direct Known Subclasses
Constant Summary collapse
- NameError =
Class.new(StandardError)
Instance Method Summary collapse
-
#initialize(base, options = {}) ⇒ SitemapNamer
constructor
Params: base - string or symbol that forms the base of the generated filename.
-
#next ⇒ Object
Increment count and return self.
-
#previous ⇒ Object
Decrement count and return self.
-
#reset ⇒ Object
Reset count to the starting index.
- #start? ⇒ Boolean
- #to_s ⇒ Object
Constructor Details
#initialize(base, options = {}) ⇒ SitemapNamer
Params:
base - string or symbol that forms the base of the generated filename
Options include:
:extension - Default: '.xml.gz'. File extension to append.
:start - Default: 1. Numerical index at which to start counting.
19 20 21 22 23 24 25 26 |
# File 'lib/sitemap_generator/sitemap_namer.rb', line 19 def initialize(base, ={}); @options = SitemapGenerator::Utilities.reverse_merge(, :extension => '.xml.gz', :start => 1 ) @base = base reset end |
Instance Method Details
#next ⇒ Object
Increment count and return self
33 34 35 36 |
# File 'lib/sitemap_generator/sitemap_namer.rb', line 33 def next @count += 1 self end |
#previous ⇒ Object
Decrement count and return self
39 40 41 42 43 |
# File 'lib/sitemap_generator/sitemap_namer.rb', line 39 def previous raise NameError, "Already at the start of the series" if start? @count -= 1 self end |
#reset ⇒ Object
Reset count to the starting index
46 47 48 |
# File 'lib/sitemap_generator/sitemap_namer.rb', line 46 def reset @count = @options[:start] end |
#start? ⇒ Boolean
50 51 52 |
# File 'lib/sitemap_generator/sitemap_namer.rb', line 50 def start? @count <= @options[:start] end |
#to_s ⇒ Object
28 29 30 |
# File 'lib/sitemap_generator/sitemap_namer.rb', line 28 def to_s "#{@base}#{@count}#{@options[:extension]}" end |