Class: BigSitemap::Builder

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

Direct Known Subclasses

IndexBuilder

Constant Summary collapse

MAX_URLS =
50000
HEADER_NAME =
'urlset'
HEADER_ATTRIBUTES =
{
  'xmlns' => 'http://www.sitemaps.org/schemas/sitemap/0.9',
  '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/sitemap.xsd"
}

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ Builder

Returns a new instance of Builder.



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/big_sitemap/builder.rb', line 14

def initialize(options)
  @gzip           = options.delete(:gzip)
  @max_urls       = options.delete(:max_urls) || MAX_URLS
  @type           = options.delete(:type)
  @filepaths      = []
  @parts          = options.delete(:start_part_id) || 0
  @partial_update = options.delete(:partial_update)

  @filename         = options.delete(:filename)
  @current_filename = nil
  @tmp_filename     = nil
  @target           = _get_writer

  @level = 0
  @opened_tags = []
  _init_document
end

Instance Method Details

#add_url!(location, options = {}) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/big_sitemap/builder.rb', line 32

def add_url!(location, options={})
  _rotate(options[:id]) if @max_urls == @urls
  _open_tag 'url'

  tag! 'loc', location
  tag! 'lastmod', options[:last_modified].utc.strftime('%Y-%m-%dT%H:%M:%S+00:00') if options[:last_modified]
  tag! 'changefreq', options[:change_frequency] || 'weekly'
  tag! 'priority', options[:priority] if options[:priority]

  _close_tag 'url'

  @urls += 1
end

#close!Object



50
51
52
53
54
55
# File 'lib/big_sitemap/builder.rb', line 50

def close!
  _close_document
  target!.close if target!.respond_to?(:close)
  File.delete(@current_filename) if File.exists?(@current_filename)
  File.rename(@tmp_filename, @current_filename)
end

#filepaths!Object



46
47
48
# File 'lib/big_sitemap/builder.rb', line 46

def filepaths!
  @filepaths
end

#target!Object



57
58
59
# File 'lib/big_sitemap/builder.rb', line 57

def target!
  @target
end