2007-02-15
■ [ruby] 海外で入れてるgemを曝すのが流行ってるらしいらしいですよ
ということでやってみた。
yhara@meteor:~/src/ruby/gem_survey % gem list|grep '^[a-zA-Z]' activesupport (1.4.0) hoe (1.1.7, 1.1.6, 1.1.3) hpricot (0.5, 0.4.92, 0.4) mechanize (0.6.4, 0.6.3, 0.3.1) narf (0.7.3) newgem (0.7.2) rake (0.7.1) redgreen (1.2) rspec (0.7.5.1, 0.7.5, 0.7.4, 0.2.0) rubyforge (0.4.0, 0.3.2, 0.3.1) scrapi (1.2.0) sources (0.0.1) tidy (1.1.2) wirble (0.1.2) ZenTest (3.4.3, 3.4.2)
すくねえw
まぁgemで入れたライブラリでちゃんと使ってるのってrspec, hpricot, mechanizeくらいだもんなぁ。
海外で晒されているリストには聞いたことないgemも一杯あってどれがどういうgemなのか知りたくなったけど、 一個ずつ調べるのも面倒なのでスクリプトを書いてみた。
(1)gemリストをtxtに保存
yhara@meteor:~/src/ruby/gem_survey % cat bryan.txt actionmailer (1.3.2, 1.3.1, 1.2.5) actionpack (1.13.2, 1.13.1, 1.12.5) ...(省略)
(2)こんなスクリプト
yhara@meteor:~/src/ruby/gem_survey % cat survey.rb
ARGF.each do |line|
name = line.split.first
puts `gem query -r -n "\\A#{name}\\z"`.split(/\n/).slice(3..-1) || "(gem #{name} not found)"
$stdout.flush
end
(3)実行すると各gemの1行解説が読めます
yhara@meteor:~/src/ruby/gem_survey % ruby survey.rb < bryan.txt| tee tmp.txt
actionmailer (1.3.2, 1.3.1, 1.3.0, 1.2.5, 1.2.4, 1.2.3, 1.2.2, 1.2.1, 1.2.0, 1.1.5, 1.1.4, 1.1.3, 1.1.2, 1.1.1, 1.0.1, 1.0.0, 0.9.1, 0.9.0, 0.8.1, 0.8.0, 0.7.1, 0.7.0, 0.6.1, 0.6.0, 0.5.0, 0.4.0, 0.3.0)
Service layer for easy email delivery and testing.
actionpack (1.13.2, 1.13.1, 1.13.0, 1.12.5, 1.12.4, 1.12.3, 1.12.2, 1.12.1, 1.12.0, 1.11.2, 1.11.1, 1.11.0, 1.10.2, 1.10.1, 1.9.1, 1.9.0, 1.8.1, 1.8.0, 1.7.0, 1.6.0, 1.5.1, 1.5.0, 1.4.0, 1.3.1, 1.3.0, 1.2.0, 1.1.0, 1.0.1, 1.0.0, 0.9.5, 0.9.0, 0.8.5, 0.8.0, 0.7.9, 0.7.8, 0.7.7, 0.7.6, 0.7.5)
Web-flow and rendering framework putting the VC in MVC.
...(省略)
■ [Plagger] Publish::PipeがYAMLを吐けるようにしてみた
PRaggerに対して「それCustomFeed::Script/Filter::Pipe/Publish::Pipeでよくね?」と思ってたんだが、 実はPublish::PipeだとタイトルとURLしか扱えないことに気付いた。
というわけで、Publish::PipeがYAMLを吐けるようにするパッチ。
5a6
> use Data::Serializer;
20,22c21,29
< for my $entry ($args->{feed}->entries) {
< print $out $self->convert($entry->title) . "\n";
< print $out $self->convert($entry->permalink) . "\n\n";
---
> if ($self->conf->{yaml}) {
> my $serializer = Data::Serializer->new(serializer => 'YAML');
> print $out $serializer->raw_serialize(Plagger::Walker->serialize($args->{feed}));
> }
> else {
> for my $entry ($args->{feed}->entries) {
> print $out $self->convert($entry->title) . "\n";
> print $out $self->convert($entry->permalink) . "\n\n";
> }
config.yamlに
- module: Publish::Pipe
config:
command: ruby sample_publish_pipe.rb
yaml: 1
みたいに書いておくと(yaml: 1 が重要)、
---
author: yhara
description: ''
language: ~
link: http://mono.kmc.gr.jp/~yhara/d/
meta: {}
source_xml: "<?xml version=\"1.0\" encoding=\"UTF-8\"?>(略)"
tags: []
title: Greenbear Diary
type: feed
url: http://mono.kmc.gr.jp/~yhara/d/index.rdf
entries:
-
author: yhara
body: "<h3>(中略)ツッコミを入れる</a></p>"
date: 2007-02-15T06:26:38+09:00
enclosures: []
feed_link: http://mono.kmc.gr.jp/~yhara/d/
id: http://mono.kmc.gr.jp/~yhara/d/?date=20070215#p01
link: http://mono.kmc.gr.jp/~yhara/d/?date=20070215#p01
meta: {}
rate: 0
summary: "ということでやってみた。(略)"
tags:
- ruby
title: "海外で入れてるgemを曝すのが流行ってるらしいらしいですよ"
widgets: []
-
author: yhara
...
みたいなYAMLがRubyスクリプトに入力されます。あとは require 'yaml'; data = YAML.load(ARGF.read) とかしてお好きにどうぞ。
もちろんYAMLが読める言語ならPythonでもJavaでもPHPでもなんでもOKです。
[ツッコミを入れる]