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, #bytesize, #empty?, #file_can_fit?, #finalize!, #full_path, #full_url, #lastmod

Methods included from Helper

#w3c_date

Constructor Details

#initialize(*args) ⇒ SitemapIndexFile

Returns a new instance of 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 = <<-HTML
    <?xml version="1.0" encoding="UTF-8"?>
      <sitemapindex
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9
          http://www.sitemaps.org/schemas/sitemap/0.9/siteindex.xsd"
        xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"
      >
  HTML
  @xml_wrapper_start.gsub!(/\s+/, ' ').gsub!(/ *> */, '>').strip!
  @xml_wrapper_end   = %q[</sitemapindex>]
  self.filesize = bytesize(@xml_wrapper_start) + bytesize(@xml_wrapper_end)
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