Class: SitemapGenerator::Builder::SitemapIndexFile

Inherits:
SitemapFile
  • Object
show all
Defined in:
lib/sitemap_generator/builder/sitemap_index_file.rb

Instance Attribute Summary

Attributes inherited from SitemapFile

#filesize, #hostname, #link_count, #public_path, #sitemap_path

Instance Method Summary collapse

Methods inherited from SitemapFile

#add_link, #empty?, #file_can_fit?, #finalize!, #full_path, #full_url, #lastmod

Methods included from Helper

#w3c_date

Constructor Details

#initialize(*args) ⇒ SitemapIndexFile


5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/sitemap_generator/builder/sitemap_index_file.rb', line 5

def initialize(*args)
  super(*args)

  @xml_content = '' # XML urlset content
  @xml_wrapper_start = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<sitemapindex\nxmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\nxsi:schemaLocation=\"http://www.sitemaps.org/schemas/sitemap/0.9\nhttp://www.sitemaps.org/schemas/sitemap/0.9/siteindex.xsd\"\nxmlns=\"http://www.sitemaps.org/schemas/sitemap/0.9\"\n>\n"
  @xml_wrapper_start.gsub!(/\s+/, ' ').gsub!(/ *> */, '>').strip!
  @xml_wrapper_end   = %q[</sitemapindex>]
  self.filesize = @xml_wrapper_start.length + @xml_wrapper_end.length
end

Instance Method Details

#build_xml(builder, link) ⇒ Object

Return XML as a String


24
25
26
27
28
29
30
# File 'lib/sitemap_generator/builder/sitemap_index_file.rb', line 24

def build_xml(builder, link)
  builder.sitemap do
    builder.loc        link[:loc]
    builder.lastmod    w3c_date(link[:lastmod])   if link[:lastmod]
  end
  builder << ''
end