2
require "rss/dublincore"
8
TAXO_NS = "http://purl.org/rss/1.0/modules/taxonomy/"
7
TAXO_URI = "http://purl.org/rss/1.0/modules/taxonomy/"
10
Element.install_ns(TAXO_PREFIX, TAXO_NS)
9
RDF.install_ns(TAXO_PREFIX, TAXO_URI)
14
13
%w(link).each do |name|
15
14
full_name = "#{TAXO_PREFIX}_#{name}"
16
BaseListener.install_get_text_element(TAXO_NS, name, "#{full_name}=")
17
TAXO_ELEMENTS << "#{TAXO_PREFIX}_#{name}"
21
attr_writer(*%w(title description creator subject publisher
22
contributor date format identifier source
23
language relation coverage rights
24
).collect{|name| "#{TAXO_PREFIX}_#{name}"})
27
class Channel; extend TaxonomyModel; end
28
class Item; extend TaxonomyModel; end
29
class Image; extend TaxonomyModel; end
30
class TextInput; extend TaxonomyModel; end
15
BaseListener.install_get_text_element(TAXO_URI, name, "#{full_name}=")
16
TAXO_ELEMENTS << "#{TAXO_PREFIX}_#{name}"
19
%w(topic topics).each do |name|
20
class_name = Utils.to_class_name(name)
21
BaseListener.install_class_name(TAXO_URI, name, "Taxonomy#{class_name}")
22
TAXO_ELEMENTS << "#{TAXO_PREFIX}_#{name}"
25
module TaxonomyTopicsModel
28
def self.append_features(klass)
31
var_name = "#{TAXO_PREFIX}_topics"
32
klass.install_have_child_element(var_name)
35
def taxo_validate(tags)
40
raise TooMuchTagError.new(tag, tag_name)
45
raise UnknownTagError.new(tag, TAXO_URI)
50
class TaxonomyTopics < Element
67
install_have_child_element("Bag")
69
install_must_call_validator('rdf', ::RSS::RDF::URI)
71
def initialize(bag=Bag.new)
77
tag_name_with_prefix(TAXO_PREFIX)
80
def maker_target(target)
84
def to_s(need_convert=true, indent=calc_indent)
85
rv = tag(indent) do |next_indent|
87
Bag_element(need_convert, next_indent),
88
other_element(need_convert, next_indent),
95
@Bag.lis.collect do |li|
110
rv << [::RSS::RDF::URI, 'Bag'] unless @Bag.nil?
114
def rdf_validate(tags)
115
_validate(tags, [["Bag", nil]])
120
module TaxonomyTopicModel
123
def self.append_features(klass)
125
var_name = "#{TAXO_PREFIX}_topic"
126
klass.install_have_children_element(var_name)
129
def taxo_validate(tags)
132
raise UnknownTagError.new(tag, TAXO_URI)
137
class TaxonomyTopic < Element
140
include DublinCoreModel
141
include TaxonomyTopicsModel
155
install_get_attribute("about", ::RSS::RDF::URI, true)
156
install_text_element("#{TAXO_PREFIX}_link")
158
def initialize(about=nil)
164
tag_name_with_prefix(TAXO_PREFIX)
167
def to_s(need_convert=true, indent=calc_indent)
168
rv = tag(indent) do |next_indent|
170
other_element(need_convert, next_indent),
175
def taxo_validate(tags)
176
elements = %w(link topics)
180
if elements.include?(tag)
183
raise TooMuchTagError.new(tag, tag_name) if counter[tag] > 1
185
raise UnknownTagError.new(tag, TAXO_URI)
190
def maker_target(target)
191
target.new_taxo_topic
196
[@taxo_link, @taxo_topics]
201
["#{RDF::PREFIX}:about", true, "about"]
207
rv << [TAXO_URI, "link"] unless @taxo_link.nil?
208
rv << [TAXO_URI, "topics"] unless @taxo_topics.nil?
215
include TaxonomyTopicModel
217
include TaxonomyTopicsModel
219
class Item; include TaxonomyTopicsModel; end