/tools/Ruby/lib/ruby/1.8/rss/taxonomy.rb

http://github.com/agross/netopenspace · Ruby · 145 lines · 114 code · 31 blank · 0 comment · 3 complexity · 90c47eb70cdb895afa24dd82642dab28 MD5 · raw file

  1. require "rss/1.0"
  2. require "rss/dublincore"
  3. module RSS
  4. TAXO_PREFIX = "taxo"
  5. TAXO_URI = "http://purl.org/rss/1.0/modules/taxonomy/"
  6. RDF.install_ns(TAXO_PREFIX, TAXO_URI)
  7. TAXO_ELEMENTS = []
  8. %w(link).each do |name|
  9. full_name = "#{TAXO_PREFIX}_#{name}"
  10. BaseListener.install_get_text_element(TAXO_URI, name, full_name)
  11. TAXO_ELEMENTS << "#{TAXO_PREFIX}_#{name}"
  12. end
  13. %w(topic topics).each do |name|
  14. class_name = Utils.to_class_name(name)
  15. BaseListener.install_class_name(TAXO_URI, name, "Taxonomy#{class_name}")
  16. TAXO_ELEMENTS << "#{TAXO_PREFIX}_#{name}"
  17. end
  18. module TaxonomyTopicsModel
  19. extend BaseModel
  20. def self.append_features(klass)
  21. super
  22. klass.install_must_call_validator(TAXO_PREFIX, TAXO_URI)
  23. %w(topics).each do |name|
  24. klass.install_have_child_element(name, TAXO_URI, "?",
  25. "#{TAXO_PREFIX}_#{name}")
  26. end
  27. end
  28. class TaxonomyTopics < Element
  29. include RSS10
  30. Bag = ::RSS::RDF::Bag
  31. class << self
  32. def required_prefix
  33. TAXO_PREFIX
  34. end
  35. def required_uri
  36. TAXO_URI
  37. end
  38. end
  39. @tag_name = "topics"
  40. install_have_child_element("Bag", RDF::URI, nil)
  41. install_must_call_validator('rdf', RDF::URI)
  42. def initialize(*args)
  43. if Utils.element_initialize_arguments?(args)
  44. super
  45. else
  46. super()
  47. self.Bag = args[0]
  48. end
  49. self.Bag ||= Bag.new
  50. end
  51. def full_name
  52. tag_name_with_prefix(TAXO_PREFIX)
  53. end
  54. def maker_target(target)
  55. target.taxo_topics
  56. end
  57. def resources
  58. if @Bag
  59. @Bag.lis.collect do |li|
  60. li.resource
  61. end
  62. else
  63. []
  64. end
  65. end
  66. end
  67. end
  68. module TaxonomyTopicModel
  69. extend BaseModel
  70. def self.append_features(klass)
  71. super
  72. var_name = "#{TAXO_PREFIX}_topic"
  73. klass.install_have_children_element("topic", TAXO_URI, "*", var_name)
  74. end
  75. class TaxonomyTopic < Element
  76. include RSS10
  77. include DublinCoreModel
  78. include TaxonomyTopicsModel
  79. class << self
  80. def required_prefix
  81. TAXO_PREFIX
  82. end
  83. def required_uri
  84. TAXO_URI
  85. end
  86. end
  87. @tag_name = "topic"
  88. install_get_attribute("about", ::RSS::RDF::URI, true, nil, nil,
  89. "#{RDF::PREFIX}:about")
  90. install_text_element("link", TAXO_URI, "?", "#{TAXO_PREFIX}_link")
  91. def initialize(*args)
  92. if Utils.element_initialize_arguments?(args)
  93. super
  94. else
  95. super()
  96. self.about = args[0]
  97. end
  98. end
  99. def full_name
  100. tag_name_with_prefix(TAXO_PREFIX)
  101. end
  102. def maker_target(target)
  103. target.new_taxo_topic
  104. end
  105. end
  106. end
  107. class RDF
  108. include TaxonomyTopicModel
  109. class Channel
  110. include TaxonomyTopicsModel
  111. end
  112. class Item; include TaxonomyTopicsModel; end
  113. end
  114. end