Qiita Teams that are logged in
You are not logged in to any team

Log in to Qiita Team
Community
OrganizationAdvent CalendarQiitadon (β)
Service
Qiita JobsQiita ZineQiita Blog
4
Help us understand the problem. What is going on with this article?
@Feel-Physics

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

More than 5 years have passed since last update.

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
Help us understand the problem. What is going on with this article?
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Feel-Physics
今はHoloLensのアプリを開発しており、技術記事はすべてブログ( http://weed.nagoya )に書いています。以前はSwift、OpenCV+Python、JavaScript、Objective-Cを書いていました。

Comments

No comments
Sign up for free and join this conversation.
Sign Up
If you already have a Qiita account Login
4
Help us understand the problem. What is going on with this article?