Sha256: d69d194796bbc946b26addda1a6e3591764d713857adfcc76a73bd2a0002275d
Contents?: true
Size: 1.19 KB
Versions: 1
Compression:
Stored size: 1.19 KB
Contents
class Knj::Google_sitemap attr_reader :doc def initialize(args = {}) @args = args #used for Time.iso8601. require "time" @doc = REXML::Document.new @doc << REXML::XMLDecl.new("1.0", "UTF-8") @urlset = @doc.add_element("urlset") @urlset.add_attributes("xmlns" => "http://www.sitemaps.org/schemas/sitemap/0.9") end def add_url(url_value, lastmod_value, cf_value = nil, priority_value = nil) el = REXML::Element.new("url") loc = el.add_element("loc") loc.text = url_value if !lastmod_value or lastmod_value.to_i == 0 raise sprintf("Invalid date: %1$s, url: %2$s", lastmod_value.to_s, url_value) end lm = el.add_element("lastmod") if @args.key?(:date_min) and @args[:date_min] > lastmod_value lastmod_value = @args[:date_min] end lm.text = lastmod_value.iso8601 if cf_value cf = el.add_element("changefreq") cf.text = cf_value end if priority_value priority = el.add_element("priority") priority.text = priority_value end @doc.root << el end def to_xml return @doc.to_s end def to_s return @doc.to_s end def write writer = REXML::Formatters::Pretty.new(5) writer.write(@doc, $stdout) end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
knjrbfw-0.0.8 | lib/knj/google_sitemap.rb |