summaryrefslogtreecommitdiff
path: root/lib/rss/2.0.rb
blob: c6c6db58a7460030d6eccf93972349a86f78fb4c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
require "rss/0.9"

module RSS

	class Rss

		class Channel

			%w(generator ttl).each do |x|
				install_text_element(x)
				install_model(x, '?')
			end

			%w(category).each do |x|
				install_have_child_element(x)
				install_model(x, '?')
			end

			[
				["image", "?"],
				["language", "?"],
			].each do |x, occurs|
				install_model(x, occurs)
			end

			def other_element(convert, indent='')
				rv = <<-EOT
#{indent}#{category_element(convert)}
#{indent}#{generator_element(convert)}
#{indent}#{ttl_element(convert)}
EOT
				rv << super
			end
			
			private
			alias children09 children
			def children
				children09 + [@category].compact
			end

			alias _tags09 _tags
			def _tags
				%w(generator ttl category).delete_if do |x|
					send(x).nil?
				end.collect do |elem|
					[nil, elem]
				end + _tags09
			end

			Category = Item::Category

			class Item
			
				[
					["comments", "?"],
					["author", "?"],
				].each do |x, occurs|
					install_text_element(x)
					install_model(x, occurs)
				end

				[
					["pubDate", '?'],
				].each do |x, occurs|
					install_date_element(x, 'rfc822')
					install_model(x, occurs)
				end

				[
					["guid", '?'],
				].each do |x, occurs|
					install_have_child_element(x)
					install_model(x, occurs)
				end
			
				def other_element(convert, indent='')
					rv = <<-EOT
#{indent}#{author_element(false)}
#{indent}#{comments_element(false)}
#{indent}#{pubDate_element(false)}
#{indent}#{guid_element(false)}
EOT
					rv << super
				end

				private
				alias children09 children
				def children
					children09 + [@guid].compact
				end

				alias _tags09 _tags
				def _tags
					%w(comments author pubDate guid).delete_if do |x|
						send(x).nil?
					end.collect do |elem|
						[nil, elem]
					end + _tags09
				end

				class Guid < Element
					
					include RSS09

					[
						["isPermaLink", nil, false]
					].each do |name, uri, required|
						install_get_attribute(name, uri, required)
					end

					content_setup

					def initialize(isPermaLink=nil, content=nil)
						super()
						@isPermaLink = isPermaLink
						@content = content
					end

					def to_s(convert=true)
						if @content
							rv = %Q!<guid!
							rv << %Q! isPermaLink="#{h @isPermaLink}"! if @isPermaLink
							rv << %Q!>#{h @content}</guid>!
							rv = @converter.convert(rv) if convert and @converter
							rv
						else
							''
						end
					end

					private
					def _attrs
						[
							["isPermaLink", false]
						]
					end

				end

			end

		end

	end

	RSS09::ELEMENTS.each do |x|
		BaseListener.install_get_text_element(x, nil, "#{x}=")
	end

end