Class: SiteMaps::Builder::URLSet
- Inherits:
-
Object
- Object
- SiteMaps::Builder::URLSet
- Defined in:
- lib/site_maps/builder/url_set.rb
Constant Summary collapse
- SCHEMAS =
{ "image" => "http://www.google.com/schemas/sitemap-image/1.1", "mobile" => "http://www.google.com/schemas/sitemap-mobile/1.0", "news" => "http://www.google.com/schemas/sitemap-news/0.9", "pagemap" => "http://www.google.com/schemas/sitemap-pagemap/1.0", "video" => "http://www.google.com/schemas/sitemap-video/1.1" }.freeze
- HEADER =
<<~HEADER <?xml version="1.0" encoding="UTF-8"?> <urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xhtml="http://www.w3.org/1999/xhtml" xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd" #{SCHEMAS.map { |name, uri| " xmlns:#{name}=\"#{uri}\"" }.join("\n")} > HEADER
- FOOTER =
"</urlset>"- FOOTER_BYTESIZE =
FOOTER.bytesize
Instance Attribute Summary collapse
-
#content ⇒ Object
readonly
Returns the value of attribute content.
-
#links_count ⇒ Object
readonly
Returns the value of attribute links_count.
-
#news_count ⇒ Object
readonly
Returns the value of attribute news_count.
Instance Method Summary collapse
- #add(link, **options) ⇒ Object
- #empty? ⇒ Boolean
- #finalize! ⇒ Object
- #finalized? ⇒ Boolean
-
#initialize ⇒ URLSet
constructor
A new instance of URLSet.
- #last_modified ⇒ Object
- #to_xml ⇒ Object
Constructor Details
Instance Attribute Details
#content ⇒ Object (readonly)
Returns the value of attribute content.
25 26 27 |
# File 'lib/site_maps/builder/url_set.rb', line 25 def content @content end |
#links_count ⇒ Object (readonly)
Returns the value of attribute links_count.
25 26 27 |
# File 'lib/site_maps/builder/url_set.rb', line 25 def links_count @links_count end |
#news_count ⇒ Object (readonly)
Returns the value of attribute news_count.
25 26 27 |
# File 'lib/site_maps/builder/url_set.rb', line 25 def news_count @news_count end |
Instance Method Details
#add(link, **options) ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/site_maps/builder/url_set.rb', line 35 def add(link, **) raise SiteMaps::FullSitemapError if finalized? url = SiteMaps::Builder::URL.new(link, **) raise SiteMaps::FullSitemapError unless fit?(url) content.puts(url.to_xml) @links_count += 1 @news_count += 1 if url.news? if (lastmod = url.last_modified) @last_modified ||= lastmod @last_modified = lastmod if lastmod > @last_modified end url end |
#empty? ⇒ Boolean
70 71 72 |
# File 'lib/site_maps/builder/url_set.rb', line 70 def empty? links_count.zero? end |
#finalize! ⇒ Object
51 52 53 54 55 56 57 58 |
# File 'lib/site_maps/builder/url_set.rb', line 51 def finalize! return if finalized? content.puts(FOOTER) @to_xml = content.string.freeze content.close @to_xml end |
#finalized? ⇒ Boolean
66 67 68 |
# File 'lib/site_maps/builder/url_set.rb', line 66 def finalized? defined?(@to_xml) end |
#last_modified ⇒ Object
74 75 76 |
# File 'lib/site_maps/builder/url_set.rb', line 74 def last_modified @last_modified || Time.now end |
#to_xml ⇒ Object
60 61 62 63 64 |
# File 'lib/site_maps/builder/url_set.rb', line 60 def to_xml return content.string + FOOTER unless finalized? @to_xml end |