Class: BetterSeo::Sitemap::Builder
- Inherits:
-
Object
- Object
- BetterSeo::Sitemap::Builder
- Includes:
- Enumerable
- Defined in:
- lib/better_seo/sitemap/builder.rb
Instance Attribute Summary collapse
-
#urls ⇒ Object
readonly
Returns the value of attribute urls.
Instance Method Summary collapse
- #add_url(location, lastmod: nil, changefreq: "weekly", priority: 0.5) ⇒ Object
- #add_urls(locations, lastmod: nil, changefreq: "weekly", priority: 0.5) ⇒ Object
- #clear ⇒ Object
- #each(&block) ⇒ Object
- #empty? ⇒ Boolean
-
#initialize(urls: []) ⇒ Builder
constructor
A new instance of Builder.
- #remove_url(location) ⇒ Object
- #size ⇒ Object
- #to_xml ⇒ Object
- #validate! ⇒ Object
Constructor Details
#initialize(urls: []) ⇒ Builder
Returns a new instance of Builder.
10 11 12 |
# File 'lib/better_seo/sitemap/builder.rb', line 10 def initialize(urls: []) @urls = urls end |
Instance Attribute Details
#urls ⇒ Object (readonly)
Returns the value of attribute urls.
8 9 10 |
# File 'lib/better_seo/sitemap/builder.rb', line 8 def urls @urls end |
Instance Method Details
#add_url(location, lastmod: nil, changefreq: "weekly", priority: 0.5) ⇒ Object
14 15 16 17 |
# File 'lib/better_seo/sitemap/builder.rb', line 14 def add_url(location, lastmod: nil, changefreq: "weekly", priority: 0.5) @urls << UrlEntry.new(location, lastmod: lastmod, changefreq: changefreq, priority: priority) self end |
#add_urls(locations, lastmod: nil, changefreq: "weekly", priority: 0.5) ⇒ Object
19 20 21 22 23 24 |
# File 'lib/better_seo/sitemap/builder.rb', line 19 def add_urls(locations, lastmod: nil, changefreq: "weekly", priority: 0.5) locations.each do |location| add_url(location, lastmod: lastmod, changefreq: changefreq, priority: priority) end self end |
#clear ⇒ Object
31 32 33 34 |
# File 'lib/better_seo/sitemap/builder.rb', line 31 def clear @urls = [] self end |
#each(&block) ⇒ Object
60 61 62 |
# File 'lib/better_seo/sitemap/builder.rb', line 60 def each(&block) @urls.each(&block) end |
#empty? ⇒ Boolean
56 57 58 |
# File 'lib/better_seo/sitemap/builder.rb', line 56 def empty? @urls.empty? end |
#remove_url(location) ⇒ Object
26 27 28 29 |
# File 'lib/better_seo/sitemap/builder.rb', line 26 def remove_url(location) @urls.reject! { |url| url.loc == location } self end |
#size ⇒ Object
52 53 54 |
# File 'lib/better_seo/sitemap/builder.rb', line 52 def size @urls.size end |
#to_xml ⇒ Object
36 37 38 39 40 41 42 43 44 45 |
# File 'lib/better_seo/sitemap/builder.rb', line 36 def to_xml xml = [] xml << '<?xml version="1.0" encoding="UTF-8"?>' xml << '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">' @urls.each do |url| xml << url.to_xml end xml << "</urlset>" xml.join("\n") end |
#validate! ⇒ Object
47 48 49 50 |
# File 'lib/better_seo/sitemap/builder.rb', line 47 def validate! @urls.each(&:validate!) true end |