Class: RSS::Rss
- Includes:
- RSS09, RootElementMixin
- Defined in:
- lib/rss/2.0.rb,
lib/rss/0.9.rb,
lib/rss/itunes.rb,
lib/rss/trackback.rb,
lib/rss/content/2.0.rb,
lib/rss/dublincore/2.0.rb
Overview
RSS 2.0 support
RSS has three different versions. This module contains support for version 2.0
Producing RSS 2.0
Producing our own RSS feeds is easy as well. Let’s make a very basic feed:
require "rss"
rss = RSS::Maker.make("2.0") do |maker|
maker.channel.language = "en"
maker.channel. = "matz"
maker.channel.updated = Time.now.to_s
maker.channel.link = "http://www.ruby-lang.org/en/feeds/news.rss"
maker.channel.title = "Example Feed"
maker.channel.description = "A longer description of my feed."
maker.items.new_item do |item|
item.link = "http://www.ruby-lang.org/en/news/2010/12/25/ruby-1-9-2-p136-is-released/"
item.title = "Ruby 1.9.2-p136 is released"
item.updated = Time.now.to_s
end
end
puts rss
As you can see, this is a very Builder-like DSL. This code will spit out an RSS 2.0 feed with one item. If we needed a second item, we’d make another block with maker.items.new_item and build a second one.
Defined Under Namespace
Classes: Channel
Constant Summary
Constants included from RSS09
RSS::RSS09::ELEMENTS, RSS::RSS09::NSPOOL
Constants inherited from Element
Element::GET_ATTRIBUTES, Element::HAVE_CHILDREN_ELEMENTS, Element::INDENT, Element::MODELS, Element::MUST_CALL_VALIDATORS, Element::NEED_INITIALIZE_VARIABLES, Element::PLURAL_FORMS, Element::TO_ELEMENT_METHODS
Instance Attribute Summary collapse
-
#feed_version ⇒ Object
(also: #rss_version=)
writeonly
Sets the attribute feed_version.
Attributes included from RootElementMixin
#encoding, #feed_subtype, #feed_type, #feed_version, #output_encoding, #standalone, #version
Attributes included from XMLStyleSheetMixin
Attributes inherited from Element
Instance Method Summary collapse
- #image ⇒ Object
-
#initialize(feed_version, version = nil, encoding = nil, standalone = nil) ⇒ Rss
constructor
A new instance of Rss.
- #items ⇒ Object
- #setup_maker_elements(maker) ⇒ Object
- #textinput ⇒ Object
Methods included from RootElementMixin
#feed_info, #setup_maker, #to_atom, #to_feed, #to_rss, #to_xml
Methods included from RSS09
Methods inherited from Element
add_have_children_element, add_need_initialize_variable, add_plural_form, add_to_element_method, content_setup, #convert, #converter=, def_corresponded_attr_reader, def_corresponded_attr_writer, #full_name, get_attributes, have_children_elements, have_content?, #have_xml_content?, inherited, inherited_base, install_get_attribute, install_model, install_must_call_validator, install_ns, models, must_call_validators, #need_base64_encode?, need_initialize_variables, need_parent?, plural_forms, required_prefix, required_uri, #set_next_element, tag_name, #tag_name, to_element_methods, #to_s, #valid?, #validate, #validate_for_stream
Methods included from BaseModel
#install_date_element, #install_have_child_element, #install_have_children_element, #install_text_element
Methods included from Utils
element_initialize_arguments?, get_file_and_line_from_caller, new_with_value_if_need, to_class_name
Methods included from Utils::InheritedReader
#inherited_array_reader, #inherited_hash_reader, #inherited_reader
Methods included from SetupMaker
Constructor Details
#initialize(feed_version, version = nil, encoding = nil, standalone = nil) ⇒ Rss
Returns a new instance of Rss.
63 64 65 66 |
# File 'lib/rss/0.9.rb', line 63 def initialize(feed_version, version=nil, encoding=nil, standalone=nil) super @feed_type = "rss" end |
Instance Attribute Details
#feed_version=(value) ⇒ Object (writeonly) Also known as: rss_version=
Sets the attribute feed_version
59 60 61 |
# File 'lib/rss/0.9.rb', line 59 def feed_version=(value) @feed_version = value end |
Instance Method Details
#image ⇒ Object
76 77 78 79 80 81 82 |
# File 'lib/rss/0.9.rb', line 76 def image if @channel @channel.image else nil end end |
#items ⇒ Object
68 69 70 71 72 73 74 |
# File 'lib/rss/0.9.rb', line 68 def items if @channel @channel.items else [] end end |
#setup_maker_elements(maker) ⇒ Object
92 93 94 95 96 97 98 99 |
# File 'lib/rss/0.9.rb', line 92 def setup_maker_elements(maker) super items.each do |item| item.setup_maker(maker.items) end image.setup_maker(maker) if image textinput.setup_maker(maker) if textinput end |
#textinput ⇒ Object
84 85 86 87 88 89 90 |
# File 'lib/rss/0.9.rb', line 84 def textinput if @channel @channel.textInput else nil end end |