LoginSignup
4
4

More than 5 years have passed since last update.

Rubyのrssライブラリをのぞいてみる

Last updated at Posted at 2013-02-07

RSS::Makerクラス

rss/Maker/base.rb

class Base

  • new_itemメソッド

    @items << item

class RSSBase < Base

クラスメソッド
  • make(*args, &block)メソッド

    new(*args).make(&block)

    下のinitializeメソッドとmakeメソッドを呼んでいる

    feed= RSS::Maker.make("2.0") do |feed|
    

    のように使う

インスタンスメソッド
  • initialize(feed_version)メソッド
  • makeメソッド

    yield(self)
    to_feed
    

class ChannelBase < Base

新しいフィードを作る際に、以下のように使う

feed.channel.about = about
feed.channel.title = title
feed.channel.description = description
feed.channel.link = link
feed.channel.language = language
  • aboutメソッド

    attr_accessor about

  • titleメソッド

    def title=(new_value)
      @title.content = new_value
    end
    
  • descriptionメソッド

    def description=(new_value)
      @description.content = new_value
    end
    
  • dateメソッド

    attr_accessor date

  • languageメソッド

    attr_accessor language

class ItemsBase < Base

新しいフィードを作る際に、以下のように使う

items.each do |feed_item|
  i= output_feed.items.new_item
  i.title       = item.title
  i.link        = item.link
  i.description = item.description
  i.date        = item.date
end
  • do_sortメソッド, max_sizeメソッド

    attr_accessor :do_sort, :max_size

RSS::Parserクラス

rss/parser.rb

class Parser

クラスメソッド
  • parse(rss, do_validate=true, ignore_unknow_element=true)メソッド

    parser = new(rss, default_parser)
    parser.do_validate = do_validate
    parser.ignore_unknown_element = ignore_unknown_element
    parser.parse

以下のように使う

feed = Net::HTTP.get(host, path).force_encoding('utf-8')
begin
  @feed = RSS::Parser.parse(feed)
rescue RSS::InvalidRSSError
  @feed = RSS::Parser.parse(feed, false )
end

ブログやってます:PAPA-tronix !

4
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
4