[#6862] Re: http_get.rb — 青山 和光 <PXN11625@...>

In-Reply-To: [ruby-list:6844] Re: http_get.rb

15 messages 1998/03/01

[#6906] ruby's Icon ? — 藤本尚邦 / FUJIMOTO Hisakuni <hisa@...>

藤本です、こんにちは。

25 messages 1998/03/03
[#6907] Re: ruby's Icon ? — matz@... (Yukihiro Matsumoto) 1998/03/03

まつもと ゆきひろです

[#6908] Re: ruby's Icon ? — 藤本尚邦 / FUJIMOTO Hisakuni <hisa@...> 1998/03/03

藤本です、こんにちは。

[#6911] Re: ruby's Icon ? — OZAWA Sakuro <ozawa@...> 1998/03/03

小澤さくです。

[#6912] Re: ruby's Icon ? — 藤本尚邦 / FUJIMOTO Hisakuni <hisa@...> 1998/03/03

藤本です、こんにちは。

[#6914] Re: ruby's Icon ? — 藤本尚邦 / FUJIMOTO Hisakuni <hisa@...> 1998/03/03

藤本です、こんばんは。

[#6918] manual 1.18b index — WATANABE Tetsuya <tetsu@...>

ruby-man-1.1b8 で、name タグがついているものを拾い集めて

17 messages 1998/03/04
[#6921] Re: manual 1.18b index — matz@... (Yukihiro Matsumoto) 1998/03/04

まつもと ゆきひろです

[#6954] Re: ruby's Icon ? — nosuzuki@... (Norio Suzuki)

こんばんは。鈴木教郎です。

18 messages 1998/03/04
[#6964] Re: ruby's Icon ? — matz@... (Yukihiro Matsumoto) 1998/03/05

まつもと ゆきひろです

[#7023] infinity — Tadayoshi Funaba <tadf@...>

ふなばです。

41 messages 1998/03/09
[#7029] Re: infinity — shugo@... (Shugo Maeda) 1998/03/09

前田です。

[#7033] Re: infinity — keiju@... (石塚圭樹 ) 1998/03/09

けいじゅ@日本ラショナルソフトウェアです.

[#7041] Re: infinity — Kazuhisa YANAGAWA <katze@...> 1998/03/10

In message <199803091741.CAA05774.keiju@cupmail0.rational.com>

[#7048] Re: infinity — keiju@... (Keiju ISHITSUKA) 1998/03/10

けいじゅ@日本ラショナルソフトウェアです.

[#7049] Re: infinity — matz@... (Yukihiro Matsumoto) 1998/03/10

まつもと ゆきひろです

[#7051] Re: infinity — keiju@... (石塚圭樹 ) 1998/03/10

けいじゅ@日本ラショナルソフトウェアです.

[#7054] Re: infinity — matz@... (Yukihiro Matsumoto) 1998/03/10

まつもと ゆきひろです

[#7050] Re: infinity — Kazuhisa YANAGAWA <katze@...> 1998/03/10

In message <199803100359.MAA08628.keiju@cupmail0.rational.com>

[#7259] Socket#shutdown — keiju@... (Keiju ISHITSUKA)

けいじゅ@日本ラショナルソフトウェアです.

16 messages 1998/03/28
[#7260] Re: Socket#shutdown — matz@... (Yukihiro Matsumoto) 1998/03/28

まつもと ゆきひろです

[#7265] Re: Socket#shutdown — keiju@... (石塚圭樹 ) 1998/03/29

けいじゅ@日本ラショナルソフトウェアです.

[ruby-list:7204] sort-schedule.rb (Re: call for scripts)

From: Takao KAWAMURA <kawamura@...>
Date: 1998-03-23 02:56:44 UTC
List: ruby-list #7204
> もっと良いものがあるかもしれないと考え,実例集に載せられるよ
> うなrubyスクリプトを募集します.

自分しか使えないようなスクリプトを書き散らしているだけなので、
ネタがなくて困っていたのですが、mailing-listに参加していて応
募しないのも残念なので、とりあえず。

EmacsのM-x diaryで使うスケジュールファイルを日付順にソートす
るスクリプトです。diaryに書けるすべてのスタイルに対応してい
るわけではなく、私が使っているスタイルしかサポートしていませ
ん(このあたりがいい加減。万が一ご要望があれば対応します)。

標準入力から読んで標準出力に書くのですが、.emacsで次のような
設定をして使うことを想定しています。

(global-set-key "\C-zc"
                (function
                 (lambda ()
                   (interactive)
                   (widen)
                   (shell-command-on-region
                    (point-min) (point-max) "sort-schedule.rb" t t))))

---------- ここから ----------
#!/usr/local/bin/ruby

# 次の形式のスケジュールをソートする
# 
# day   style: Month day, year [time] text
# week  style: Week [time] text
# year  style: Month day [time] text
# month style: * day [time] text
# 
# これらの形式をこの順に並べ、各形式の中では日付が若いものほど前に並べ
# る。ただし、day styleの過去のスケジュールは末尾に配置する。各形式間
# は空行で区切る。

class Schedule
    # kind以外はソートのためにpublicにする
    attr("year")
    attr("month")
    attr("day")
    attr("week")
    attr("hour")
    attr("min")
    attr("past")                # 過去のデータなら1
    attr("kind")

    def initialize(line)
        @year = 9999
        @month = 12
        @day = 32
        @week = 8
        @hour = 0
        @min = 0
        @past = 0
        @line = line

        a = line.sub(/^&/,"").split(' ')
        case s = a.shift
        when /^\*$/
            @kind = "month"
            @day = a.shift.to_i
        when /^(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)$/
            @month = {"Jan" => 1, "Feb" => 2, "Mar" =>3, "Apr" => 4,
                "May" => 5, "Jun" => 6, "Jul" =>7, "Aug" => 8,
                "Sep" => 9, "Oct" => 10, "Nov" =>11, "Dec" => 12}[s]
            s = a.shift
            @kind = "year"
            if s =~ /.*,/
                @kind = "day"
                s.chop!
                @year = a.shift.to_i
                @past = 1 if Time.now >= Time.local(@year,@month,s.to_i+1)
            end
            @day = s.to_i
        when /^(Sun|Mon|Tues|Wednes|Thirs|Fri|Satur)day$/
            @kind = "week"
            @week = {"Sunday" => 0, "Monday" => 1, "Tuesday" => 2,
                "Wednesday" => 3, "Thirsday" => 4, "Friday" => 5,
                "Saturday" => 6}[s]
        else
            $stderr.print $0, " :illeagal line: ", line
        end
        if a[0] =~ /^(\d\d):(\d\d)$/
            @hour = $1.to_i
            @min = $2.to_i
        end
    end

    def <=>(other)
        ret = past - other.past
        ret = year - other.year if ret == 0
        ret = week - other.week if ret == 0
        ret = month - other.month if ret == 0
        ret = day - other.day if ret == 0
        ret = hour - other.hour if ret == 0
        ret = min - other.min if ret == 0
        ret
    end

    def to_s
        @line
    end
end

schedules = []
while gets
    schedules.push(Schedule.new($_)) unless /^$/
end

schedules.sort!

lastKind = nil
schedules.each do |x|
    print "\n" if x.kind != lastKind
    print x
    lastKind = x.kind
end
---------- ここまで ----------

-- 
川村 尚生 / 鳥取大学 工学部 知能情報工学科

In This Thread