rss 0.2.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (54) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +9 -0
  3. data/.travis.yml +6 -0
  4. data/Gemfile +6 -0
  5. data/LICENSE.txt +22 -0
  6. data/README.md +88 -0
  7. data/Rakefile +10 -0
  8. data/bin/console +14 -0
  9. data/bin/setup +8 -0
  10. data/lib/rss.rb +92 -0
  11. data/lib/rss/0.9.rb +462 -0
  12. data/lib/rss/1.0.rb +485 -0
  13. data/lib/rss/2.0.rb +143 -0
  14. data/lib/rss/atom.rb +1025 -0
  15. data/lib/rss/content.rb +34 -0
  16. data/lib/rss/content/1.0.rb +10 -0
  17. data/lib/rss/content/2.0.rb +12 -0
  18. data/lib/rss/converter.rb +171 -0
  19. data/lib/rss/dublincore.rb +164 -0
  20. data/lib/rss/dublincore/1.0.rb +13 -0
  21. data/lib/rss/dublincore/2.0.rb +13 -0
  22. data/lib/rss/dublincore/atom.rb +17 -0
  23. data/lib/rss/image.rb +198 -0
  24. data/lib/rss/itunes.rb +413 -0
  25. data/lib/rss/maker.rb +79 -0
  26. data/lib/rss/maker/0.9.rb +509 -0
  27. data/lib/rss/maker/1.0.rb +436 -0
  28. data/lib/rss/maker/2.0.rb +224 -0
  29. data/lib/rss/maker/atom.rb +173 -0
  30. data/lib/rss/maker/base.rb +945 -0
  31. data/lib/rss/maker/content.rb +22 -0
  32. data/lib/rss/maker/dublincore.rb +122 -0
  33. data/lib/rss/maker/entry.rb +164 -0
  34. data/lib/rss/maker/feed.rb +427 -0
  35. data/lib/rss/maker/image.rb +112 -0
  36. data/lib/rss/maker/itunes.rb +243 -0
  37. data/lib/rss/maker/slash.rb +34 -0
  38. data/lib/rss/maker/syndication.rb +19 -0
  39. data/lib/rss/maker/taxonomy.rb +119 -0
  40. data/lib/rss/maker/trackback.rb +62 -0
  41. data/lib/rss/parser.rb +589 -0
  42. data/lib/rss/rexmlparser.rb +50 -0
  43. data/lib/rss/rss.rb +1346 -0
  44. data/lib/rss/slash.rb +52 -0
  45. data/lib/rss/syndication.rb +69 -0
  46. data/lib/rss/taxonomy.rb +148 -0
  47. data/lib/rss/trackback.rb +291 -0
  48. data/lib/rss/utils.rb +200 -0
  49. data/lib/rss/xml-stylesheet.rb +106 -0
  50. data/lib/rss/xml.rb +72 -0
  51. data/lib/rss/xmlparser.rb +95 -0
  52. data/lib/rss/xmlscanner.rb +122 -0
  53. data/rss.gemspec +38 -0
  54. metadata +138 -0
@@ -0,0 +1,436 @@
1
+ # frozen_string_literal: false
2
+ require_relative "../1.0"
3
+
4
+ require_relative "base"
5
+
6
+ module RSS
7
+ module Maker
8
+
9
+ class RSS10 < RSSBase
10
+
11
+ def initialize(feed_version="1.0")
12
+ super
13
+ @feed_type = "rss"
14
+ end
15
+
16
+ private
17
+ def make_feed
18
+ RDF.new(@version, @encoding, @standalone)
19
+ end
20
+
21
+ def setup_elements(rss)
22
+ setup_channel(rss)
23
+ setup_image(rss)
24
+ setup_items(rss)
25
+ setup_textinput(rss)
26
+ end
27
+
28
+ class Channel < ChannelBase
29
+ include SetupDefaultLanguage
30
+
31
+ def to_feed(rss)
32
+ set_default_values do
33
+ _not_set_required_variables = not_set_required_variables
34
+ if _not_set_required_variables.empty?
35
+ channel = RDF::Channel.new(@about)
36
+ setup_values(channel)
37
+ channel.dc_dates.clear
38
+ rss.channel = channel
39
+ set_parent(channel, rss)
40
+ setup_items(rss)
41
+ setup_image(rss)
42
+ setup_textinput(rss)
43
+ setup_other_elements(rss, channel)
44
+ else
45
+ raise NotSetError.new("maker.channel", _not_set_required_variables)
46
+ end
47
+ end
48
+ end
49
+
50
+ private
51
+ def setup_items(rss)
52
+ items = RDF::Channel::Items.new
53
+ seq = items.Seq
54
+ set_parent(items, seq)
55
+ target_items = @maker.items.normalize
56
+ raise NotSetError.new("maker", ["items"]) if target_items.empty?
57
+ target_items.each do |item|
58
+ li = RDF::Channel::Items::Seq::Li.new(item.link)
59
+ seq.lis << li
60
+ set_parent(li, seq)
61
+ end
62
+ rss.channel.items = items
63
+ set_parent(rss.channel, items)
64
+ end
65
+
66
+ def setup_image(rss)
67
+ if @maker.image.have_required_values?
68
+ image = RDF::Channel::Image.new(@maker.image.url)
69
+ rss.channel.image = image
70
+ set_parent(image, rss.channel)
71
+ end
72
+ end
73
+
74
+ def setup_textinput(rss)
75
+ if @maker.textinput.have_required_values?
76
+ textinput = RDF::Channel::Textinput.new(@maker.textinput.link)
77
+ rss.channel.textinput = textinput
78
+ set_parent(textinput, rss.channel)
79
+ end
80
+ end
81
+
82
+ def required_variable_names
83
+ %w(about link)
84
+ end
85
+
86
+ def not_set_required_variables
87
+ vars = super
88
+ vars << "description" unless description {|d| d.have_required_values?}
89
+ vars << "title" unless title {|t| t.have_required_values?}
90
+ vars
91
+ end
92
+
93
+ class SkipDays < SkipDaysBase
94
+ def to_feed(*args)
95
+ end
96
+
97
+ class Day < DayBase
98
+ end
99
+ end
100
+
101
+ class SkipHours < SkipHoursBase
102
+ def to_feed(*args)
103
+ end
104
+
105
+ class Hour < HourBase
106
+ end
107
+ end
108
+
109
+ class Cloud < CloudBase
110
+ def to_feed(*args)
111
+ end
112
+ end
113
+
114
+ class Categories < CategoriesBase
115
+ def to_feed(*args)
116
+ end
117
+
118
+ class Category < CategoryBase
119
+ end
120
+ end
121
+
122
+ class Links < LinksBase
123
+ def to_feed(rss, channel)
124
+ return if @links.empty?
125
+ @links.first.to_feed(rss, channel)
126
+ end
127
+
128
+ class Link < LinkBase
129
+ def to_feed(rss, channel)
130
+ if have_required_values?
131
+ channel.link = href
132
+ else
133
+ raise NotSetError.new("maker.channel.link",
134
+ not_set_required_variables)
135
+ end
136
+ end
137
+
138
+ private
139
+ def required_variable_names
140
+ %w(href)
141
+ end
142
+ end
143
+ end
144
+
145
+ class Authors < AuthorsBase
146
+ def to_feed(rss, channel)
147
+ end
148
+
149
+ class Author < AuthorBase
150
+ def to_feed(rss, channel)
151
+ end
152
+ end
153
+ end
154
+
155
+ class Contributors < ContributorsBase
156
+ def to_feed(rss, channel)
157
+ end
158
+
159
+ class Contributor < ContributorBase
160
+ end
161
+ end
162
+
163
+ class Generator < GeneratorBase
164
+ def to_feed(rss, channel)
165
+ end
166
+ end
167
+
168
+ class Copyright < CopyrightBase
169
+ def to_feed(rss, channel)
170
+ end
171
+ end
172
+
173
+ class Description < DescriptionBase
174
+ def to_feed(rss, channel)
175
+ channel.description = content if have_required_values?
176
+ end
177
+
178
+ private
179
+ def required_variable_names
180
+ %w(content)
181
+ end
182
+ end
183
+
184
+ class Title < TitleBase
185
+ def to_feed(rss, channel)
186
+ channel.title = content if have_required_values?
187
+ end
188
+
189
+ private
190
+ def required_variable_names
191
+ %w(content)
192
+ end
193
+ end
194
+ end
195
+
196
+ class Image < ImageBase
197
+ def to_feed(rss)
198
+ if @url
199
+ image = RDF::Image.new(@url)
200
+ set = setup_values(image)
201
+ if set
202
+ rss.image = image
203
+ set_parent(image, rss)
204
+ setup_other_elements(rss, image)
205
+ end
206
+ end
207
+ end
208
+
209
+ def have_required_values?
210
+ super and @maker.channel.have_required_values?
211
+ end
212
+
213
+ private
214
+ def variables
215
+ super + ["link"]
216
+ end
217
+
218
+ def required_variable_names
219
+ %w(url title link)
220
+ end
221
+ end
222
+
223
+ class Items < ItemsBase
224
+ def to_feed(rss)
225
+ if rss.channel
226
+ normalize.each do |item|
227
+ item.to_feed(rss)
228
+ end
229
+ setup_other_elements(rss, rss.items)
230
+ end
231
+ end
232
+
233
+ class Item < ItemBase
234
+ def to_feed(rss)
235
+ set_default_values do
236
+ item = RDF::Item.new(link)
237
+ set = setup_values(item)
238
+ if set
239
+ item.dc_dates.clear
240
+ rss.items << item
241
+ set_parent(item, rss)
242
+ setup_other_elements(rss, item)
243
+ elsif !have_required_values?
244
+ raise NotSetError.new("maker.item", not_set_required_variables)
245
+ end
246
+ end
247
+ end
248
+
249
+ private
250
+ def required_variable_names
251
+ %w(link)
252
+ end
253
+
254
+ def variables
255
+ super + %w(link)
256
+ end
257
+
258
+ def not_set_required_variables
259
+ set_default_values do
260
+ vars = super
261
+ vars << "title" unless title {|t| t.have_required_values?}
262
+ vars
263
+ end
264
+ end
265
+
266
+ class Guid < GuidBase
267
+ def to_feed(*args)
268
+ end
269
+ end
270
+
271
+ class Enclosure < EnclosureBase
272
+ def to_feed(*args)
273
+ end
274
+ end
275
+
276
+ class Source < SourceBase
277
+ def to_feed(*args)
278
+ end
279
+
280
+ class Authors < AuthorsBase
281
+ def to_feed(*args)
282
+ end
283
+
284
+ class Author < AuthorBase
285
+ end
286
+ end
287
+
288
+ class Categories < CategoriesBase
289
+ def to_feed(*args)
290
+ end
291
+
292
+ class Category < CategoryBase
293
+ end
294
+ end
295
+
296
+ class Contributors < ContributorsBase
297
+ def to_feed(*args)
298
+ end
299
+
300
+ class Contributor < ContributorBase
301
+ end
302
+ end
303
+
304
+ class Generator < GeneratorBase
305
+ def to_feed(*args)
306
+ end
307
+ end
308
+
309
+ class Icon < IconBase
310
+ def to_feed(*args)
311
+ end
312
+ end
313
+
314
+ class Links < LinksBase
315
+ def to_feed(*args)
316
+ end
317
+
318
+ class Link < LinkBase
319
+ end
320
+ end
321
+
322
+ class Logo < LogoBase
323
+ def to_feed(*args)
324
+ end
325
+ end
326
+
327
+ class Rights < RightsBase
328
+ def to_feed(*args)
329
+ end
330
+ end
331
+
332
+ class Subtitle < SubtitleBase
333
+ def to_feed(*args)
334
+ end
335
+ end
336
+
337
+ class Title < TitleBase
338
+ def to_feed(*args)
339
+ end
340
+ end
341
+ end
342
+
343
+ class Categories < CategoriesBase
344
+ def to_feed(*args)
345
+ end
346
+
347
+ class Category < CategoryBase
348
+ end
349
+ end
350
+
351
+ class Authors < AuthorsBase
352
+ def to_feed(*args)
353
+ end
354
+
355
+ class Author < AuthorBase
356
+ end
357
+ end
358
+
359
+ class Links < LinksBase
360
+ def to_feed(*args)
361
+ end
362
+
363
+ class Link < LinkBase
364
+ end
365
+ end
366
+
367
+ class Contributors < ContributorsBase
368
+ def to_feed(rss, item)
369
+ end
370
+
371
+ class Contributor < ContributorBase
372
+ end
373
+ end
374
+
375
+ class Rights < RightsBase
376
+ def to_feed(rss, item)
377
+ end
378
+ end
379
+
380
+ class Description < DescriptionBase
381
+ def to_feed(rss, item)
382
+ item.description = content if have_required_values?
383
+ end
384
+
385
+ private
386
+ def required_variable_names
387
+ %w(content)
388
+ end
389
+ end
390
+
391
+ class Content < ContentBase
392
+ def to_feed(rss, item)
393
+ end
394
+ end
395
+
396
+ class Title < TitleBase
397
+ def to_feed(rss, item)
398
+ item.title = content if have_required_values?
399
+ end
400
+
401
+ private
402
+ def required_variable_names
403
+ %w(content)
404
+ end
405
+ end
406
+ end
407
+ end
408
+
409
+ class Textinput < TextinputBase
410
+ def to_feed(rss)
411
+ if @link
412
+ textinput = RDF::Textinput.new(@link)
413
+ set = setup_values(textinput)
414
+ if set
415
+ rss.textinput = textinput
416
+ set_parent(textinput, rss)
417
+ setup_other_elements(rss, textinput)
418
+ end
419
+ end
420
+ end
421
+
422
+ def have_required_values?
423
+ super and @maker.channel.have_required_values?
424
+ end
425
+
426
+ private
427
+ def required_variable_names
428
+ %w(title description name link)
429
+ end
430
+ end
431
+ end
432
+
433
+ add_maker("1.0", "1.0", RSS10)
434
+ add_maker("rss1.0", "1.0", RSS10)
435
+ end
436
+ end
@@ -0,0 +1,224 @@
1
+ # frozen_string_literal: false
2
+ require_relative "../2.0"
3
+
4
+ require_relative "0.9"
5
+
6
+ module RSS
7
+ module Maker
8
+
9
+ class RSS20 < RSS09
10
+
11
+ def initialize(feed_version="2.0")
12
+ super
13
+ end
14
+
15
+ class Channel < RSS09::Channel
16
+
17
+ private
18
+ def required_variable_names
19
+ %w(link)
20
+ end
21
+
22
+ class SkipDays < RSS09::Channel::SkipDays
23
+ class Day < RSS09::Channel::SkipDays::Day
24
+ end
25
+ end
26
+
27
+ class SkipHours < RSS09::Channel::SkipHours
28
+ class Hour < RSS09::Channel::SkipHours::Hour
29
+ end
30
+ end
31
+
32
+ class Cloud < RSS09::Channel::Cloud
33
+ def to_feed(rss, channel)
34
+ cloud = Rss::Channel::Cloud.new
35
+ set = setup_values(cloud)
36
+ if set
37
+ channel.cloud = cloud
38
+ set_parent(cloud, channel)
39
+ setup_other_elements(rss, cloud)
40
+ end
41
+ end
42
+
43
+ private
44
+ def required_variable_names
45
+ %w(domain port path registerProcedure protocol)
46
+ end
47
+ end
48
+
49
+ class Categories < RSS09::Channel::Categories
50
+ def to_feed(rss, channel)
51
+ @categories.each do |category|
52
+ category.to_feed(rss, channel)
53
+ end
54
+ end
55
+
56
+ class Category < RSS09::Channel::Categories::Category
57
+ def to_feed(rss, channel)
58
+ category = Rss::Channel::Category.new
59
+ set = setup_values(category)
60
+ if set
61
+ channel.categories << category
62
+ set_parent(category, channel)
63
+ setup_other_elements(rss, category)
64
+ end
65
+ end
66
+
67
+ private
68
+ def required_variable_names
69
+ %w(content)
70
+ end
71
+ end
72
+ end
73
+
74
+ class Generator < GeneratorBase
75
+ def to_feed(rss, channel)
76
+ channel.generator = content
77
+ end
78
+
79
+ private
80
+ def required_variable_names
81
+ %w(content)
82
+ end
83
+ end
84
+ end
85
+
86
+ class Image < RSS09::Image
87
+ private
88
+ def required_element?
89
+ false
90
+ end
91
+ end
92
+
93
+ class Items < RSS09::Items
94
+ class Item < RSS09::Items::Item
95
+ private
96
+ def required_variable_names
97
+ []
98
+ end
99
+
100
+ def not_set_required_variables
101
+ vars = super
102
+ if !title {|t| t.have_required_values?} and
103
+ !description {|d| d.have_required_values?}
104
+ vars << "title or description"
105
+ end
106
+ vars
107
+ end
108
+
109
+ def variables
110
+ super + ["pubDate"]
111
+ end
112
+
113
+ class Guid < RSS09::Items::Item::Guid
114
+ def to_feed(rss, item)
115
+ guid = Rss::Channel::Item::Guid.new
116
+ set = setup_values(guid)
117
+ if set
118
+ item.guid = guid
119
+ set_parent(guid, item)
120
+ setup_other_elements(rss, guid)
121
+ end
122
+ end
123
+
124
+ private
125
+ def required_variable_names
126
+ %w(content)
127
+ end
128
+ end
129
+
130
+ class Enclosure < RSS09::Items::Item::Enclosure
131
+ def to_feed(rss, item)
132
+ enclosure = Rss::Channel::Item::Enclosure.new
133
+ set = setup_values(enclosure)
134
+ if set
135
+ item.enclosure = enclosure
136
+ set_parent(enclosure, item)
137
+ setup_other_elements(rss, enclosure)
138
+ end
139
+ end
140
+
141
+ private
142
+ def required_variable_names
143
+ %w(url length type)
144
+ end
145
+ end
146
+
147
+ class Source < RSS09::Items::Item::Source
148
+ def to_feed(rss, item)
149
+ source = Rss::Channel::Item::Source.new
150
+ set = setup_values(source)
151
+ if set
152
+ item.source = source
153
+ set_parent(source, item)
154
+ setup_other_elements(rss, source)
155
+ end
156
+ end
157
+
158
+ private
159
+ def required_variable_names
160
+ %w(url content)
161
+ end
162
+
163
+ class Links < RSS09::Items::Item::Source::Links
164
+ def to_feed(rss, source)
165
+ return if @links.empty?
166
+ @links.first.to_feed(rss, source)
167
+ end
168
+
169
+ class Link < RSS09::Items::Item::Source::Links::Link
170
+ def to_feed(rss, source)
171
+ source.url = href
172
+ end
173
+ end
174
+ end
175
+ end
176
+
177
+ class Categories < RSS09::Items::Item::Categories
178
+ def to_feed(rss, item)
179
+ @categories.each do |category|
180
+ category.to_feed(rss, item)
181
+ end
182
+ end
183
+
184
+ class Category < RSS09::Items::Item::Categories::Category
185
+ def to_feed(rss, item)
186
+ category = Rss::Channel::Item::Category.new
187
+ set = setup_values(category)
188
+ if set
189
+ item.categories << category
190
+ set_parent(category, item)
191
+ setup_other_elements(rss)
192
+ end
193
+ end
194
+
195
+ private
196
+ def required_variable_names
197
+ %w(content)
198
+ end
199
+ end
200
+ end
201
+
202
+ class Authors < RSS09::Items::Item::Authors
203
+ def to_feed(rss, item)
204
+ return if @authors.empty?
205
+ @authors.first.to_feed(rss, item)
206
+ end
207
+
208
+ class Author < RSS09::Items::Item::Authors::Author
209
+ def to_feed(rss, item)
210
+ item.author = name
211
+ end
212
+ end
213
+ end
214
+ end
215
+ end
216
+
217
+ class Textinput < RSS09::Textinput
218
+ end
219
+ end
220
+
221
+ add_maker("2.0", "2.0", RSS20)
222
+ add_maker("rss2.0", "2.0", RSS20)
223
+ end
224
+ end