Class: SimpleSitemapGenerator::Generator

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeGenerator

Returns a new instance of Generator.



19
20
21
22
23
24
25
26
27
28
29
# File 'lib/simple_sitemap_generator.rb', line 19

def initialize
  @default_changefreq = 'daily'
  @default_priority = 0.5
  @inappropriate_paths = [
    /:/,  # ignore paths like 'users/:id', 'pages/:page'
    /sitemap\.xml/,
  ]
  @host = ''
  @options = {}
  @additional_paths = []
end

Instance Attribute Details

#additional_pathsObject

Returns the value of attribute additional_paths.



5
6
7
# File 'lib/simple_sitemap_generator.rb', line 5

def additional_paths
  @additional_paths
end

#default_changefreqObject

Returns the value of attribute default_changefreq.



5
6
7
# File 'lib/simple_sitemap_generator.rb', line 5

def default_changefreq
  @default_changefreq
end

#default_lastmodObject

Returns the value of attribute default_lastmod.



5
6
7
# File 'lib/simple_sitemap_generator.rb', line 5

def default_lastmod
  @default_lastmod
end

#default_priorityObject

Returns the value of attribute default_priority.



5
6
7
# File 'lib/simple_sitemap_generator.rb', line 5

def default_priority
  @default_priority
end

#hostObject

Returns the value of attribute host.



5
6
7
# File 'lib/simple_sitemap_generator.rb', line 5

def host
  @host
end

#inappropriate_pathsObject

Returns the value of attribute inappropriate_paths.



5
6
7
# File 'lib/simple_sitemap_generator.rb', line 5

def inappropriate_paths
  @inappropriate_paths
end

#optionsObject

Returns the value of attribute options.



5
6
7
# File 'lib/simple_sitemap_generator.rb', line 5

def options
  @options
end

Instance Method Details

#generate_xmlObject



7
8
9
10
11
12
13
14
15
16
17
# File 'lib/simple_sitemap_generator.rb', line 7

def generate_xml
  paths.map { |path| {
      loc: @host + path,
      lastmod: @options[path.to_sym]&.[](:lastmod) || @default_lastmod,
      changefreq: @options[path.to_sym]&.[](:changefreq) || @default_changefreq,
      priority: @options[path.to_sym]&.[](:priority) || @default_priority,
    }.compact }
    .to_xml(root: 'url', skip_types: true)
    .gsub(default_root_start_tag, root_start_tag)
    .gsub(default_root_end_tag, root_end_tag)
end