Class: EasySitemap::Generator

Inherits:
Object
  • Object
show all
Defined in:
lib/easy_sitemap/generator.rb

Instance Method Summary collapse

Constructor Details

#initialize(entities_scope, options = {}) ⇒ Generator

Returns a new instance of Generator.



4
5
6
7
# File 'lib/easy_sitemap/generator.rb', line 4

def initialize(entities_scope, options = {})
  @entities_scope = entities_scope
  @options = options
end

Instance Method Details

#to_xmlObject



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/easy_sitemap/generator.rb', line 9

def to_xml
  builder = Nokogiri::XML::Builder.new do |xml|
    xml.urlset do
      @entities_scope.find_each(batch_size: 1) do |entity|
        xml.url do
          xml.loc url(entity)
          if entity.respond_to?(:updated_at)
            xml.lastmod entity.updated_at
          elsif entity.respond_to?(:updated_on)
            xml.lastmod entity.updated_on
          end
        end
      end
    end
  end
  builder.to_xml
end