Class: SitemapGenerator::SitemapNamer

Inherits:
Object
  • Object
show all
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

SimpleNamer, SitemapIndexNamer

Constant Summary collapse

NameError =
Class.new(StandardError)

Instance Method Summary collapse

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={});
  @options = SitemapGenerator::Utilities.reverse_merge(options,
    :extension => '.xml.gz',
    :start => 1
  )
  @base = base
  reset
end

Instance Method Details

#nextObject

Increment count and return self



33
34
35
36
# File 'lib/sitemap_generator/sitemap_namer.rb', line 33

def next
  @count += 1
  self
end

#previousObject

Decrement count and return self

Raises:



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

#resetObject

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

Returns:

  • (Boolean)


50
51
52
# File 'lib/sitemap_generator/sitemap_namer.rb', line 50

def start?
  @count <= @options[:start]
end

#to_sObject



28
29
30
# File 'lib/sitemap_generator/sitemap_namer.rb', line 28

def to_s
  "#{@base}#{@count}#{@options[:extension]}"
end