キーワード
- getoptlong (12)
-
net
/ imap (12) -
net
/ pop (12) -
net
/ smtp (12) - open-uri (12)
- optparse (12)
- pp (12)
- prime (12)
- profile (6)
-
rinda
/ rinda (12) - rss (12)
- tsort (12)
-
webrick
/ cgi (12) -
win32
/ registry (12) - yaml (12)
検索結果
先頭5件
-
rss (61.0)
-
RSS を扱うためのライブラリです。
...数のフィードを扱う場合は以下のようにし、す
べてのフィードをRSS 2.0のように扱うことができます。
feeds.each do |xml|
rss20 = RSS::Parser.parse(xml).to_feed("rss2.0")
...
end
また、to_feedは以下のように書くことも出来ます。......するために、以下のようにブロックを
使用することが出来ます。
rss10 = feed.to_rss("1.0") do |maker|
maker.items.each do |item|
item.title.content ||= "No title"
end
end
to_feedのブロック内で出来ることを理解するためには、to_feedが......ます。
require 'rss'
パースするフィードはファイルに保存されていて引数で与えられるものとします。
ARGV.each do |fname|
feed = nil
begin
feed = RSS::Parser.parse(File.read(fname), false)
rescue RSS::Error
end
if feed.nil?
p... -
tsort (49.0)
-
tsort はトポロジカルソートと強連結成分に関するモジュールを提供します。
...を提供します。
=== Example
//emlist[][ruby]{
require 'tsort'
class Hash
include TSort
alias tsort_each_node each_key
def tsort_each_child(node, &block)
fetch(node).each(&block)
end
end
{1=>[2, 3], 2=>[3], 3=>[], 4=>[]}.tsort
#=> [3, 2, 1, 4]
{1=>[2], 2=>[3, 4], 3=>[2], 4=>[]}......ult = []
end
def rule(outputs, inputs=[], &block)
triple = [outputs, inputs, block]
outputs.each {|f| @dep[f] = [triple]}
@dep[triple] = inputs
end
def build(target)
each_strongly_connected_component_from(target) {|ns|
if ns.length != 1
fs = ns.delete_if {|n|......if inputs_time != nil && inputs_time.to_i == Time.now.to_i
block.call
end
end
}
end
def tsort_each_child(node, &block)
@dep[node].each(&block)
end
include TSort
end
def command(arg)
print arg, "\n"
system arg
end
m = Make.new
m.rule(%w[t1]) { command '... -
net
/ pop (37.0) -
このライブラリは、POP3 (Post Office Protocol version 3) を 用いてPOPサーバからメールを受信する機能を提供するライブラリです。
...pop.start('YourAccount', 'YourPassword') # POPのセッションを開始
if pop.mails.empty?
$stderr.puts 'no mail.'
else
pop.mails.each_with_index do |m, idx| # 各メッセージにアクセスする
File.open("inbox/#{idx + 1}", 'w') {|f|
f.write m.pop
}......消したりする
ことができます。Net::POP3#mails はこの Net::POPMail オブジェクトの配列であり、
Net::POP3#each_mail はさらに pop.mails.each のショートカットです。
==== 短くする
上の例はあえて省略や短縮用メソッドを避けたためにか......lse
pop.mails.each_with_index do |m, idx|
File.open("inbox/#{idx + 1}", 'w') {|f|
f.write m.pop
}
m.delete
end
$stderr.puts "#{pop.mails.size} mails popped."
end
}
Net::POP3#delete_all を使うと
さらに Net::POP3#each_mail と
Net::POPM... -
getoptlong (13.0)
-
getoptlong は、GNU の getopt_long() とまったく同じ方式でコマンド 行オプションの解析を行う Ruby のライブラリです。
...たのプログラム
に足して下さい。
begin
parser.each_option do |name, arg|
eval "$OPT_#{name.sub(/^--/, '').gsub(/-/, '_').upcase} = '#{arg}'"
end
rescue
exit(1)
end
each_option メソッドは、常にオプション名を「正式名 (canoni... -
net
/ imap (13.0) -
このライブラリは Internet Message Access Protocol (IMAP) の クライアントライブラリです。2060 を元に 実装されています。
...map = Net::IMAP.new('mail.example.com')
imap.authenticate('LOGIN', 'joe_user', 'joes_password')
imap.examine('INBOX')
imap.search(["RECENT"]).each do |message_id|
envelope = imap.fetch(message_id, "ENVELOPE")[0].attr["ENVELOPE"]
puts "#{envelope.from[0].name}: \t#{envelope.subject}"......if not imap.list('Mail/', 'sent-apr03')
imap.create('Mail/sent-apr03')
end
imap.search(["BEFORE", "30-Apr-2003", "SINCE", "1-Apr-2003"]).each do |message_id|
imap.copy(message_id, "Mail/sent-apr03")
imap.store(message_id, "+FLAGS", [:Deleted])
end
imap.expunge
=== スレッ... -
open-uri (13.0)
-
http/ftp に簡単にアクセスするためのクラスです。
...例
http/ftp の URL を、普通のファイルのように開けます。
require 'open-uri'
open("http://www.ruby-lang.org/") {|f|
f.each_line {|line| p line}
}
開いたファイルオブジェクトは StringIO もしくは Tempfile で
すが OpenURI::Meta モジュールで拡張......されていて、メタ情報を獲得する
メソッドが使えます。
require 'open-uri'
open("http://www.ruby-lang.org/en") {|f|
f.each_line {|line| p line}
p f.base_uri # <URI::HTTP:0x40e6ef2 URL:http://www.ruby-lang.org/en/>
p f.content_type # "text/html"
p......http/ftp の URL を、普通のファイルのように開けます。
require 'open-uri'
URI.open("http://www.ruby-lang.org/") {|f|
f.each_line {|line| p line}
}
開いたファイルオブジェクトは StringIO もしくは Tempfile で
すが OpenURI::Meta モジュールで拡......ていて、メタ情報を獲得する
メソッドが使えます。
require 'open-uri'
URI.open("http://www.ruby-lang.org/en") {|f|
f.each_line {|line| p line}
p f.base_uri # <URI::HTTP:0x40e6ef2 URL:http://www.ruby-lang.org/en/>
p f.content_type # "text/html"
p f... -
rinda
/ rinda (13.0) -
Rubyで実装されたタプルスペース(Tuple Space)を扱うためのライブラリです。
...#{$0} <server_uri>")
DRb.start_service
ts = Rinda::TupleSpaceProxy.new(DRbObject.new(nil, uri))
(1..10).each do |n|
ts.write(['sum', DRb.uri, n])
end
(1..10).each do |n|
ans = ts.take(['ans', DRb.uri, n, nil])
p [ans[2], ans[3]]
end
この例は ruby の配布物の... -
win32
/ registry (13.0) -
win32/registry は Win32 プラットフォームでレジストリをアクセスするための ライブラリです。Win32 API の呼び出しに Win32API を使います。
...# 型指定付き値の書き込み
reg.write('foo', Win32::Registry::REG_SZ, 'bar') # 値の書き込み
reg.each_value { |name, type, data| ... } # 値の列挙
reg.each_key { |key, wtime| ... } # サブキーの列挙
reg.delete_value('foo')... -
net
/ smtp (7.0) -
メールを送信するためのプロトコル SMTP (Simple Mail Transfer Protocol) を扱うライブラリです。
...==== 文字列以外からの送信
ひとつ上の例では文字列リテラル (ヒアドキュメント) を使って送信しましたが、
each メソッドを持ったオブジェクトからならなんでも送ることができます。
以下は File オブジェクトから直接送...