Class: SitemapGenerator::Builder::SitemapIndexUrl

Inherits:
SitemapUrl
  • Object
show all
Defined in:
lib/sitemap_generator/builder/sitemap_index_url.rb

Overview

Wraps a sitemap file reference as a <sitemap> XML entry for use in a sitemap index.

Instance Method Summary collapse

Methods inherited from SitemapUrl

#news?

Constructor Details

#initialize(path, options = {}) ⇒ SitemapIndexUrl

Returns a new instance of SitemapIndexUrl.



9
10
11
12
13
14
15
16
# File 'lib/sitemap_generator/builder/sitemap_index_url.rb', line 9

def initialize(path, options = {})
  if (index = path.is_a?(SitemapGenerator::Builder::SitemapIndexFile) && path)
    options = SitemapGenerator::Utilities.reverse_merge(options, host: index.location.host, lastmod: Time.now,
                                                                 priority: 1.0)
    path = index.location.path_in_public
  end
  super
end

Instance Method Details

#to_xml(builder = nil) ⇒ Object

Return the URL as XML



19
20
21
22
23
24
25
26
# File 'lib/sitemap_generator/builder/sitemap_index_url.rb', line 19

def to_xml(builder = nil)
  builder = ::Builder::XmlMarkup.new if builder.nil?
  builder.sitemap do
    builder.loc        self[:loc]
    builder.lastmod    w3c_date(self[:lastmod]) if self[:lastmod]
  end
  builder << '' # force to string
end