Rioが使いたくて
日本語のサイトがなんやら見当たらないので,海外をうろつくも,ほとんど何も無し.記事があってもhttp://rio.rubyforge.org/の紹介だったり.
「コレはコレ」ということで括るしか無いのか.まぁこれから模索していけば良いだけの話なんですけども.
何ができそうかな?とりあえずWebを絡めると楽しそうではある.とりあえず,Uchが振ってくれたこれでもやってみるか….
- urlかpathの指定でイケルようにする
- とりあえずcatする
なんか簡単そう.
require 'rubygems' require 'rio' # 以降省略 path = ARGV.shift lines = [] rio(path) > lines lines.each do |l| puts l end
これで動いた.
$ ruby cat.rb cat.rb require 'rubygems' require 'rio' path = ARGV.shift -以下略- $ ruby cat.rb 'http://d.hatena.ne.jp/omochist/' <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=euc-jp"> <meta http-equiv="Content-Style-Type" content="text/css"> -以下もの凄く略-
おもしれー.ついでにheadやtailもやっちまうべ.
まずはhead
path = ARGV.shift unless n = ARGV.shift.to_i then n = 10 end rio(path).chomp.lines(0 .. (n - 1)) do |l| puts l end
次にtail
path = ARGV.shift unless n = ARGV.shift.to_i then n = 10 end lines = [] rio(path).chomp > lines tail = [] lines.reverse.each_with_index do |line, i| break if i >= n tail << line end tail.reverse.each do |l| puts l end
変に長くなった.
また何か考えよっと.