Class: SitemapGenerator::SimpleNamer
- Inherits:
-
SitemapNamer
- Object
- SitemapNamer
- SitemapGenerator::SimpleNamer
- Defined in:
- lib/sitemap_generator/sitemap_namer.rb
Overview
The SimpleNamer uses the same namer instance for the sitemap index and the sitemaps. If no index is needed, the first sitemap gets the first name. However, if an index is needed, the index gets the first name.
A typical sequence would looks like this:
* sitemap.xml.gz
* sitemap1.xml.gz
* sitemap2.xml.gz
* sitemap3.xml.gz
* ...
Arguments:
base - string or symbol that forms the base of the generated filename e.g.
if `:geo` files are generated like `geo.xml.gz`, `geo1.xml.gz`, `geo2.xml.gz` etc.
Options:
:extension - Default: '.xml.gz'. File extension to append.
:start - Default: 1. Numerical index at which to start counting.
:zero - Default: nil. A string or number that is appended to +base+
to create the first name in the sequence. So setting this
to '_index' would produce 'sitemap_index.xml.gz' as
the first name. Thereafter, the numerical index defined by +start+
is used, and subsequent names would be 'sitemap1.xml.gz', 'sitemap2.xml.gz', etc.
In these examples the `base` string is assumed to be 'sitemap'.
Constant Summary
Constants inherited from SitemapNamer
SitemapGenerator::SitemapNamer::NameError
Instance Method Summary collapse
-
#initialize(base, options = {}) ⇒ SimpleNamer
constructor
A new instance of SimpleNamer.
-
#next ⇒ Object
Return this instance set to the next name.
-
#previous ⇒ Object
Return this instance set to the previous name.
-
#reset ⇒ Object
Reset to the first name.
-
#start? ⇒ Boolean
True if on the first name.
- #to_s ⇒ Object
Constructor Details
#initialize(base, options = {}) ⇒ SimpleNamer
Returns a new instance of SimpleNamer.
89 90 91 92 93 94 |
# File 'lib/sitemap_generator/sitemap_namer.rb', line 89 def initialize(base, ={}) = SitemapGenerator::Utilities.reverse_merge(, :zero => nil # identifies the marker for the start of the series ) super(base, ) end |
Instance Method Details
#next ⇒ Object
Return this instance set to the next name
111 112 113 114 115 116 117 118 |
# File 'lib/sitemap_generator/sitemap_namer.rb', line 111 def next if start? @count = @options[:start] else @count += 1 end self end |
#previous ⇒ Object
Return this instance set to the previous name
121 122 123 124 125 126 127 128 129 |
# File 'lib/sitemap_generator/sitemap_namer.rb', line 121 def previous raise NameError, "Already at the start of the series" if start? if @count <= @options[:start] @count = @options[:zero] else @count -= 1 end self end |
#reset ⇒ Object
Reset to the first name
101 102 103 |
# File 'lib/sitemap_generator/sitemap_namer.rb', line 101 def reset @count = @options[:zero] end |
#start? ⇒ Boolean
True if on the first name
106 107 108 |
# File 'lib/sitemap_generator/sitemap_namer.rb', line 106 def start? @count == @options[:zero] end |
#to_s ⇒ Object
96 97 98 |
# File 'lib/sitemap_generator/sitemap_namer.rb', line 96 def to_s "#{@base}#{@count}#{@options[:extension]}" end |