Class: Cartographer::URL
- Inherits:
-
Object
- Object
- Cartographer::URL
- Defined in:
- lib/cartographer.rb
Overview
Cartographer::URL is a structure to enforce the sitemap format.
Constant Summary collapse
- XML_TEMPLATE =
File.("xml/sitemap_uri.haml", File.dirname(File.(__FILE__)))
Instance Attribute Summary collapse
-
#changefreq ⇒ Object
Change frequency, stored as a string.
-
#lastmod ⇒ Object
Last modification time of this item.
-
#location ⇒ Object
Location of item, stored as a kind of URI::Generic.
-
#priority ⇒ Object
Priority, stored as a Numeric object, from 0 to 1 with decimal values included.
Instance Method Summary collapse
-
#eql?(url2) ⇒ Boolean
(also: #==)
Compares two locations and returns true/false.
-
#hash ⇒ Object
Computes a hash based off the URI.
-
#initialize(args) ⇒ URL
constructor
Constructor.
-
#to_xml ⇒ Object
Convert this object to the <url>…</url> representation.
Constructor Details
#initialize(args) ⇒ URL
Constructor. Takes a hash of arguments:
- location
-
A kind of URI::Generic
- lastmod
-
A Time object which represents the last modification time.
- changefreq
-
A string which contains the frequency.
- priority
-
A decimal value (any kind of Numeric will do) from 0 - 1.
172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 |
# File 'lib/cartographer.rb', line 172 def initialize(args) args.each do |key, value| send(key.to_s + "=", value) end unless self.location raise ArgumentError, "the location argument is required." end unless self.location.kind_of?(URI::Generic) raise ArgumentError, "location must be a kind of URI::Generic" end if self.lastmod and !self.lastmod.kind_of?(Time) raise ArgumentError, "lastmod must be a kind of Time." end if self.changefreq and !self.changefreq.kind_of?(String) raise ArgumentError, "changefreq must be a kind of String" end if self.priority and !self.priority.kind_of?(Numeric) raise ArgumentError, "priority must be a kind of Numeric" end end |
Instance Attribute Details
#changefreq ⇒ Object
Change frequency, stored as a string.
157 158 159 |
# File 'lib/cartographer.rb', line 157 def changefreq @changefreq end |
#lastmod ⇒ Object
Last modification time of this item.
153 154 155 |
# File 'lib/cartographer.rb', line 153 def lastmod @lastmod end |
#location ⇒ Object
Location of item, stored as a kind of URI::Generic. Required.
149 150 151 |
# File 'lib/cartographer.rb', line 149 def location @location end |
#priority ⇒ Object
Priority, stored as a Numeric object, from 0 to 1 with decimal values included.
161 162 163 |
# File 'lib/cartographer.rb', line 161 def priority @priority end |
Instance Method Details
#eql?(url2) ⇒ Boolean Also known as: ==
Compares two locations and returns true/false.
216 217 218 |
# File 'lib/cartographer.rb', line 216 def eql?(url2) location == url2.location end |
#hash ⇒ Object
Computes a hash based off the URI.
208 209 210 |
# File 'lib/cartographer.rb', line 208 def hash location.hash end |
#to_xml ⇒ Object
Convert this object to the <url>…</url> representation.
202 203 204 |
# File 'lib/cartographer.rb', line 202 def to_xml Haml::Engine.new(File.read(XML_TEMPLATE)).render(self) end |