2015-12-16 00:07:31 -05:00
|
|
|
# frozen_string_literal: false
|
2004-01-27 22:46:13 -05:00
|
|
|
require "rss/1.0"
|
|
|
|
|
|
|
|
module RSS
|
2013-11-09 00:56:09 -05:00
|
|
|
# The prefix for the Syndication XML namespace.
|
2004-10-16 00:51:15 -04:00
|
|
|
SY_PREFIX = 'sy'
|
2013-11-09 00:56:09 -05:00
|
|
|
# The URI of the Syndication specification.
|
2004-10-16 00:51:15 -04:00
|
|
|
SY_URI = "http://purl.org/rss/1.0/modules/syndication/"
|
2004-01-27 22:46:13 -05:00
|
|
|
|
2004-10-16 00:51:15 -04:00
|
|
|
RDF.install_ns(SY_PREFIX, SY_URI)
|
2004-01-27 22:46:13 -05:00
|
|
|
|
2004-10-16 00:51:15 -04:00
|
|
|
module SyndicationModel
|
2009-03-05 22:56:38 -05:00
|
|
|
|
2004-10-16 00:51:15 -04:00
|
|
|
extend BaseModel
|
2009-03-05 22:56:38 -05:00
|
|
|
|
2004-10-16 00:51:15 -04:00
|
|
|
ELEMENTS = []
|
2009-03-05 22:56:38 -05:00
|
|
|
|
2004-10-16 00:51:15 -04:00
|
|
|
def self.append_features(klass)
|
|
|
|
super
|
2007-03-17 06:13:25 -04:00
|
|
|
|
|
|
|
klass.install_must_call_validator(SY_PREFIX, SY_URI)
|
|
|
|
klass.module_eval do
|
2005-11-24 22:43:48 -05:00
|
|
|
[
|
|
|
|
["updatePeriod"],
|
|
|
|
["updateFrequency", :positive_integer]
|
|
|
|
].each do |name, type|
|
2007-03-17 06:13:25 -04:00
|
|
|
install_text_element(name, SY_URI, "?",
|
|
|
|
"#{SY_PREFIX}_#{name}", type,
|
|
|
|
"#{SY_PREFIX}:#{name}")
|
2004-10-16 00:51:15 -04:00
|
|
|
end
|
2004-01-27 22:46:13 -05:00
|
|
|
|
2005-04-05 03:03:43 -04:00
|
|
|
%w(updateBase).each do |name|
|
2007-03-17 06:13:25 -04:00
|
|
|
install_date_element(name, SY_URI, "?",
|
|
|
|
"#{SY_PREFIX}_#{name}", 'w3cdtf',
|
|
|
|
"#{SY_PREFIX}:#{name}")
|
2004-10-16 00:51:15 -04:00
|
|
|
end
|
2007-03-17 06:13:25 -04:00
|
|
|
end
|
2004-02-03 09:01:42 -05:00
|
|
|
|
2007-03-17 06:13:25 -04:00
|
|
|
klass.module_eval(<<-EOC, __FILE__, __LINE__ + 1)
|
2004-10-16 00:51:15 -04:00
|
|
|
alias_method(:_sy_updatePeriod=, :sy_updatePeriod=)
|
|
|
|
def sy_updatePeriod=(new_value)
|
|
|
|
new_value = new_value.strip
|
|
|
|
validate_sy_updatePeriod(new_value) if @do_validate
|
|
|
|
self._sy_updatePeriod = new_value
|
|
|
|
end
|
|
|
|
EOC
|
|
|
|
end
|
2004-01-27 22:46:13 -05:00
|
|
|
|
2004-10-16 00:51:15 -04:00
|
|
|
private
|
|
|
|
SY_UPDATEPERIOD_AVAILABLE_VALUES = %w(hourly daily weekly monthly yearly)
|
2015-11-19 22:44:12 -05:00
|
|
|
def validate_sy_updatePeriod(value) # :nodoc:
|
2004-10-16 00:51:15 -04:00
|
|
|
unless SY_UPDATEPERIOD_AVAILABLE_VALUES.include?(value)
|
|
|
|
raise NotAvailableValueError.new("updatePeriod", value)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2004-01-27 22:46:13 -05:00
|
|
|
|
2004-10-16 00:51:15 -04:00
|
|
|
class RDF
|
|
|
|
class Channel; include SyndicationModel; end
|
|
|
|
end
|
2004-01-27 22:46:13 -05:00
|
|
|
|
2004-10-16 00:51:15 -04:00
|
|
|
prefix_size = SY_PREFIX.size + 1
|
|
|
|
SyndicationModel::ELEMENTS.uniq!
|
2005-04-05 03:03:43 -04:00
|
|
|
SyndicationModel::ELEMENTS.each do |full_name|
|
|
|
|
name = full_name[prefix_size..-1]
|
2007-03-17 06:13:25 -04:00
|
|
|
BaseListener.install_get_text_element(SY_URI, name, full_name)
|
2004-10-16 00:51:15 -04:00
|
|
|
end
|
2004-01-27 22:46:13 -05:00
|
|
|
|
|
|
|
end
|