Sha256: 77832a7b726f0ab1ee104d631a736145fedde0cc3d6ed7b06b086e91fde815a2

Contents?: true

Size: 934 Bytes

Versions: 3

Compression:

Stored size: 934 Bytes

Contents

# frozen_string_literal: true

module SiteMaps::Builder
  class SitemapIndex
    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
    FOOTER = "</sitemapindex>"

    attr_reader :sitemaps

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

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

    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

    def empty?
      @sitemaps.empty?
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
site_maps-0.0.1.beta3 lib/site_maps/builder/sitemap_index.rb
site_maps-0.0.1.beta2 lib/site_maps/builder/sitemap_index.rb
site_maps-0.0.1.beta1 lib/site_maps/builder/sitemap_index.rb