Class: Indexmap::Writer

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

Constant Summary collapse

VALID_FORMATS =
%i[index single_file].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(public_path:, base_url:, sections: nil, entries: nil, index_filename: "sitemap.xml", format: :index) ⇒ Writer

Returns a new instance of Writer.



7
8
9
10
11
12
13
14
# File 'lib/indexmap/writer.rb', line 7

def initialize(public_path:, base_url:, sections: nil, entries: nil, index_filename: "sitemap.xml", format: :index)
  @entries = normalize_entries(entries)
  @format = normalize_format(format)
  @sections = normalize_sections(sections)
  @public_path = Pathname(public_path)
  @base_url = base_url
  @index_filename = index_filename
end

Instance Attribute Details

#public_pathObject

Returns the value of attribute public_path.



28
29
30
# File 'lib/indexmap/writer.rb', line 28

def public_path
  @public_path
end

Instance Method Details

#writeObject



16
17
18
19
20
21
22
23
24
25
26
# File 'lib/indexmap/writer.rb', line 16

def write
  FileUtils.mkdir_p(public_path)

  return [write_file(index_filename, urlset_xml(entries))] if single_file?

  paths = sections.map do |section|
    write_file(section.filename, urlset_xml(section.entries))
  end

  paths + [write_file(index_filename, index_xml(sections))]
end