Class: SiteMaps::Builder::SitemapIndex

Inherits:
Object
  • Object
show all
Defined in:
lib/site_maps/builder/sitemap_index.rb

Defined Under Namespace

Classes: Item

Constant Summary collapse

HEADER =
<<~HEADER
  <?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"
  >
HEADER
"</sitemapindex>"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeSitemapIndex

Returns a new instance of SitemapIndex.



17
18
19
# File 'lib/site_maps/builder/sitemap_index.rb', line 17

def initialize
  @sitemaps = Concurrent::Set.new
end

Instance Attribute Details

#sitemapsObject (readonly)

Returns the value of attribute sitemaps.



15
16
17
# File 'lib/site_maps/builder/sitemap_index.rb', line 15

def sitemaps
  @sitemaps
end

Instance Method Details

#add(loc, lastmod: nil) ⇒ Object



21
22
23
24
# File 'lib/site_maps/builder/sitemap_index.rb', line 21

def add(loc, lastmod: nil)
  sitemap = loc.is_a?(Item) ? loc : Item.new(loc, lastmod)
  @sitemaps.add(sitemap)
end

#empty?Boolean

Returns:

  • (Boolean)


36
37
38
# File 'lib/site_maps/builder/sitemap_index.rb', line 36

def empty?
  @sitemaps.empty?
end

#to_xmlObject



26
27
28
29
30
31
32
33
34
# File 'lib/site_maps/builder/sitemap_index.rb', line 26

def to_xml
  io = StringIO.new
  io.puts(HEADER)
  @sitemaps.each do |sitemap|
    io.puts(sitemap.to_xml)
  end
  io.puts(FOOTER)
  io.string
end