PageRenderTime 112ms CodeModel.GetById 42ms app.highlight 63ms RepoModel.GetById 1ms app.codeStats 0ms

/tools/Ruby/lib/ruby/1.8/rss/maker/0.9.rb

http://github.com/agross/netopenspace
Ruby | 467 lines | 389 code | 78 blank | 0 comment | 18 complexity | 4c998df78d087a94366ed0640a2ce714 MD5 | raw file
  1require "rss/0.9"
  2
  3require "rss/maker/base"
  4
  5module RSS
  6  module Maker
  7    
  8    class RSS09 < RSSBase
  9      
 10      def initialize(feed_version="0.92")
 11        super
 12        @feed_type = "rss"
 13      end
 14      
 15      private
 16      def make_feed
 17        Rss.new(@feed_version, @version, @encoding, @standalone)
 18      end
 19
 20      def setup_elements(rss)
 21        setup_channel(rss)
 22      end
 23
 24      class Channel < ChannelBase
 25        def to_feed(rss)
 26          channel = Rss::Channel.new
 27          set = setup_values(channel)
 28          _not_set_required_variables = not_set_required_variables
 29          if _not_set_required_variables.empty?
 30            rss.channel = channel
 31            set_parent(channel, rss)
 32            setup_items(rss)
 33            setup_image(rss)
 34            setup_textinput(rss)
 35            setup_other_elements(rss, channel)
 36            rss
 37          else
 38            raise NotSetError.new("maker.channel", _not_set_required_variables)
 39          end
 40        end
 41        
 42        private
 43        def setup_items(rss)
 44          @maker.items.to_feed(rss)
 45        end
 46        
 47        def setup_image(rss)
 48          @maker.image.to_feed(rss)
 49        end
 50        
 51        def setup_textinput(rss)
 52          @maker.textinput.to_feed(rss)
 53        end
 54        
 55        def variables
 56          super + ["pubDate"]
 57        end
 58
 59        def required_variable_names
 60          %w(link language)
 61        end
 62
 63        def not_set_required_variables
 64          vars = super
 65          vars << "description" unless description {|d| d.have_required_values?}
 66          vars << "title" unless title {|t| t.have_required_values?}
 67          vars
 68        end
 69
 70        class SkipDays < SkipDaysBase
 71          def to_feed(rss, channel)
 72            unless @days.empty?
 73              skipDays = Rss::Channel::SkipDays.new
 74              channel.skipDays = skipDays
 75              set_parent(skipDays, channel)
 76              @days.each do |day|
 77                day.to_feed(rss, skipDays.days)
 78              end
 79            end
 80          end
 81          
 82          class Day < DayBase
 83            def to_feed(rss, days)
 84              day = Rss::Channel::SkipDays::Day.new
 85              set = setup_values(day)
 86              if set
 87                days << day
 88                set_parent(day, days)
 89                setup_other_elements(rss, day)
 90              end
 91            end
 92
 93            private
 94            def required_variable_names
 95              %w(content)
 96            end
 97          end
 98        end
 99        
100        class SkipHours < SkipHoursBase
101          def to_feed(rss, channel)
102            unless @hours.empty?
103              skipHours = Rss::Channel::SkipHours.new
104              channel.skipHours = skipHours
105              set_parent(skipHours, channel)
106              @hours.each do |hour|
107                hour.to_feed(rss, skipHours.hours)
108              end
109            end
110          end
111          
112          class Hour < HourBase
113            def to_feed(rss, hours)
114              hour = Rss::Channel::SkipHours::Hour.new
115              set = setup_values(hour)
116              if set
117                hours << hour
118                set_parent(hour, hours)
119                setup_other_elements(rss, hour)
120              end
121            end
122
123            private
124            def required_variable_names
125              %w(content)
126            end
127          end
128        end
129        
130        class Cloud < CloudBase
131          def to_feed(*args)
132          end
133        end
134
135        class Categories < CategoriesBase
136          def to_feed(*args)
137          end
138
139          class Category < CategoryBase
140          end
141        end
142
143        class Links < LinksBase
144          def to_feed(rss, channel)
145            return if @links.empty?
146            @links.first.to_feed(rss, channel)
147          end
148
149          class Link < LinkBase
150            def to_feed(rss, channel)
151              if have_required_values?
152                channel.link = href
153              else
154                raise NotSetError.new("maker.channel.link",
155                                      not_set_required_variables)
156              end
157            end
158
159            private
160            def required_variable_names
161              %w(href)
162            end
163          end
164        end
165
166        class Authors < AuthorsBase
167          def to_feed(rss, channel)
168          end
169
170          class Author < AuthorBase
171            def to_feed(rss, channel)
172            end
173          end
174        end
175
176        class Contributors < ContributorsBase
177          def to_feed(rss, channel)
178          end
179
180          class Contributor < ContributorBase
181          end
182        end
183
184        class Generator < GeneratorBase
185          def to_feed(rss, channel)
186          end
187        end
188
189        class Copyright < CopyrightBase
190          def to_feed(rss, channel)
191            channel.copyright = content if have_required_values?
192          end
193
194          private
195          def required_variable_names
196            %w(content)
197          end
198        end
199
200        class Description < DescriptionBase
201          def to_feed(rss, channel)
202            channel.description = content if have_required_values?
203          end
204
205          private
206          def required_variable_names
207            %w(content)
208          end
209        end
210
211        class Title < TitleBase
212          def to_feed(rss, channel)
213            channel.title = content if have_required_values?
214          end
215
216          private
217          def required_variable_names
218            %w(content)
219          end
220        end
221      end
222
223      class Image < ImageBase
224        def to_feed(rss)
225          image = Rss::Channel::Image.new
226          set = setup_values(image)
227          if set
228            image.link = link
229            rss.channel.image = image
230            set_parent(image, rss.channel)
231            setup_other_elements(rss, image)
232          elsif required_element?
233            raise NotSetError.new("maker.image", not_set_required_variables)
234          end
235        end
236
237        private
238        def required_variable_names
239          %w(url title link)
240        end
241
242        def required_element?
243          true
244        end
245      end
246      
247      class Items < ItemsBase
248        def to_feed(rss)
249          if rss.channel
250            normalize.each do |item|
251              item.to_feed(rss)
252            end
253            setup_other_elements(rss, rss.items)
254          end
255        end
256        
257        class Item < ItemBase
258          def to_feed(rss)
259            item = Rss::Channel::Item.new
260            set = setup_values(item)
261            _not_set_required_variables = not_set_required_variables
262            if _not_set_required_variables.empty?
263              rss.items << item
264              set_parent(item, rss.channel)
265              setup_other_elements(rss, item)
266            elsif variable_is_set?
267              raise NotSetError.new("maker.items", _not_set_required_variables)
268            end
269          end
270
271          private
272          def required_variable_names
273            []
274          end
275
276          def not_set_required_variables
277            vars = super
278            if @maker.feed_version == "0.91"
279              vars << "title" unless title {|t| t.have_required_values?}
280              vars << "link" unless link {|l| l.have_required_values?}
281            end
282            vars
283          end
284
285          class Guid < GuidBase
286            def to_feed(*args)
287            end
288          end
289
290          class Enclosure < EnclosureBase
291            def to_feed(*args)
292            end
293          end
294
295          class Source < SourceBase
296            def to_feed(*args)
297            end
298
299            class Authors < AuthorsBase
300              def to_feed(*args)
301              end
302
303              class Author < AuthorBase
304              end
305            end
306
307            class Categories < CategoriesBase
308              def to_feed(*args)
309              end
310
311              class Category < CategoryBase
312              end
313            end
314
315            class Contributors < ContributorsBase
316              def to_feed(*args)
317              end
318
319              class Contributor < ContributorBase
320              end
321            end
322
323            class Generator < GeneratorBase
324              def to_feed(*args)
325              end
326            end
327
328            class Icon < IconBase
329              def to_feed(*args)
330              end
331            end
332
333            class Links < LinksBase
334              def to_feed(*args)
335              end
336
337              class Link < LinkBase
338              end
339            end
340
341            class Logo < LogoBase
342              def to_feed(*args)
343              end
344            end
345
346            class Rights < RightsBase
347              def to_feed(*args)
348              end
349            end
350
351            class Subtitle < SubtitleBase
352              def to_feed(*args)
353              end
354            end
355
356            class Title < TitleBase
357              def to_feed(*args)
358              end
359            end
360          end
361
362          class Categories < CategoriesBase
363            def to_feed(*args)
364            end
365
366            class Category < CategoryBase
367            end
368          end
369
370          class Authors < AuthorsBase
371            def to_feed(*args)
372            end
373
374            class Author < AuthorBase
375            end
376          end
377
378          class Links < LinksBase
379            def to_feed(rss, item)
380              return if @links.empty?
381              @links.first.to_feed(rss, item)
382            end
383
384            class Link < LinkBase
385              def to_feed(rss, item)
386                if have_required_values?
387                  item.link = href
388                else
389                  raise NotSetError.new("maker.link",
390                                        not_set_required_variables)
391                end
392              end
393
394              private
395              def required_variable_names
396                %w(href)
397              end
398            end
399          end
400
401          class Contributors < ContributorsBase
402            def to_feed(rss, item)
403            end
404
405            class Contributor < ContributorBase
406            end
407          end
408
409          class Rights < RightsBase
410            def to_feed(rss, item)
411            end
412          end
413
414          class Description < DescriptionBase
415            def to_feed(rss, item)
416              item.description = content if have_required_values?
417            end
418
419            private
420            def required_variable_names
421              %w(content)
422            end
423          end
424
425          class Content < ContentBase
426            def to_feed(rss, item)
427            end
428          end
429
430          class Title < TitleBase
431            def to_feed(rss, item)
432              item.title = content if have_required_values?
433            end
434
435            private
436            def required_variable_names
437              %w(content)
438            end
439          end
440        end
441      end
442      
443      class Textinput < TextinputBase
444        def to_feed(rss)
445          textInput = Rss::Channel::TextInput.new
446          set = setup_values(textInput)
447          if set
448            rss.channel.textInput = textInput
449            set_parent(textInput, rss.channel)
450            setup_other_elements(rss, textInput)
451          end
452        end
453
454        private
455        def required_variable_names
456          %w(title description name link)
457        end
458      end
459    end
460    
461    add_maker("0.9", "0.92", RSS09)
462    add_maker("0.91", "0.91", RSS09)
463    add_maker("0.92", "0.92", RSS09)
464    add_maker("rss0.91", "0.91", RSS09)
465    add_maker("rss0.92", "0.92", RSS09)
466  end
467end