1 | require "rss/1.0"
|
---|
2 |
|
---|
3 | module RSS
|
---|
4 |
|
---|
5 | SY_PREFIX = 'sy'
|
---|
6 | SY_URI = "http://purl.org/rss/1.0/modules/syndication/"
|
---|
7 |
|
---|
8 | RDF.install_ns(SY_PREFIX, SY_URI)
|
---|
9 |
|
---|
10 | module SyndicationModel
|
---|
11 |
|
---|
12 | extend BaseModel
|
---|
13 |
|
---|
14 | ELEMENTS = []
|
---|
15 |
|
---|
16 | def self.append_features(klass)
|
---|
17 | super
|
---|
18 |
|
---|
19 | klass.install_must_call_validator(SY_PREFIX, SY_URI)
|
---|
20 | klass.module_eval do
|
---|
21 | [
|
---|
22 | ["updatePeriod"],
|
---|
23 | ["updateFrequency", :positive_integer]
|
---|
24 | ].each do |name, type|
|
---|
25 | install_text_element(name, SY_URI, "?",
|
---|
26 | "#{SY_PREFIX}_#{name}", type,
|
---|
27 | "#{SY_PREFIX}:#{name}")
|
---|
28 | end
|
---|
29 |
|
---|
30 | %w(updateBase).each do |name|
|
---|
31 | install_date_element(name, SY_URI, "?",
|
---|
32 | "#{SY_PREFIX}_#{name}", 'w3cdtf', name)
|
---|
33 | end
|
---|
34 |
|
---|
35 | alias_method(:_sy_updatePeriod=, :sy_updatePeriod=)
|
---|
36 | def sy_updatePeriod=(new_value)
|
---|
37 | new_value = new_value.strip
|
---|
38 | validate_sy_updatePeriod(new_value) if @do_validate
|
---|
39 | self._sy_updatePeriod = new_value
|
---|
40 | end
|
---|
41 | end
|
---|
42 | end
|
---|
43 |
|
---|
44 | private
|
---|
45 | SY_UPDATEPERIOD_AVAILABLE_VALUES = %w(hourly daily weekly monthly yearly)
|
---|
46 | def validate_sy_updatePeriod(value)
|
---|
47 | unless SY_UPDATEPERIOD_AVAILABLE_VALUES.include?(value)
|
---|
48 | raise NotAvailableValueError.new("updatePeriod", value)
|
---|
49 | end
|
---|
50 | end
|
---|
51 | end
|
---|
52 |
|
---|
53 | class RDF
|
---|
54 | class Channel; include SyndicationModel; end
|
---|
55 | end
|
---|
56 |
|
---|
57 | prefix_size = SY_PREFIX.size + 1
|
---|
58 | SyndicationModel::ELEMENTS.uniq!
|
---|
59 | SyndicationModel::ELEMENTS.each do |full_name|
|
---|
60 | name = full_name[prefix_size..-1]
|
---|
61 | BaseListener.install_get_text_element(SY_URI, name, "#{full_name}=")
|
---|
62 | end
|
---|
63 |
|
---|
64 | end
|
---|