Class: BigSitemap::Builder
- Inherits:
-
Object
- Object
- BigSitemap::Builder
- Defined in:
- lib/big_sitemap/builder.rb
Direct Known Subclasses
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
- #add_url!(location, options = {}) ⇒ Object
- #close! ⇒ Object
- #filepaths! ⇒ Object
-
#initialize(options) ⇒ Builder
constructor
A new instance of Builder.
- #target! ⇒ Object
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() @gzip = .delete(:gzip) @max_urls = .delete(:max_urls) || MAX_URLS @type = .delete(:type) @filepaths = [] @parts = .delete(:start_part_id) || 0 @partial_update = .delete(:partial_update) @filename = .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, ={}) _rotate([:id]) if @max_urls == @urls _open_tag 'url' tag! 'loc', location tag! 'lastmod', [:last_modified].utc.strftime('%Y-%m-%dT%H:%M:%S+00:00') if [:last_modified] tag! 'changefreq', [:change_frequency] || 'weekly' tag! 'priority', [:priority] if [: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 |