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