Class: Cartographer::URL

Inherits:
Object
  • Object
show all
Defined in:
lib/cartographer.rb

Overview

Cartographer::URL is a structure to enforce the sitemap format.

Constant Summary collapse

XML_TEMPLATE =
File.expand_path("xml/sitemap_uri.haml", File.dirname(File.expand_path(__FILE__)))

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#changefreqObject

Change frequency, stored as a string.



157
158
159
# File 'lib/cartographer.rb', line 157

def changefreq
  @changefreq
end

#lastmodObject

Last modification time of this item.



153
154
155
# File 'lib/cartographer.rb', line 153

def lastmod
  @lastmod
end

#locationObject

Location of item, stored as a kind of URI::Generic. Required.



149
150
151
# File 'lib/cartographer.rb', line 149

def location
  @location
end

#priorityObject

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.

Returns:

  • (Boolean)


216
217
218
# File 'lib/cartographer.rb', line 216

def eql?(url2)
  location == url2.location
end

#hashObject

Computes a hash based off the URI.



208
209
210
# File 'lib/cartographer.rb', line 208

def hash
  location.hash
end

#to_xmlObject

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