class TatutyuLister
このアプリケーション全体をあらわすクラス
Public Class Methods
jihun(t)
click to toggle source
# File makelist.rb, line 17 def jihun t case t when Time t.strftime('%Y年%m月%d日%H時%M分') else t.to_s end end
new(argv)
click to toggle source
# File makelist.rb, line 28 def initialize argv @curtime = Time.parse(argv.first) # TOFIX 変更できるようにしたほうがよいか(ARGVならばuntaintが必要) @infnam = 'tatutyu.ltsv' @outfnam = 'out.html' @db = [] @html = HTMLBuilder.new(' 竜巻注意情報 発表状況一覧') end
Public Instance Methods
buildpage()
click to toggle source
# File makelist.rb, line 65 def buildpage @html.header('link', 'rel'=>'stylesheet', 'type'=>'text/css', 'href'=>'t.css') @html.tag('h1') { @html.puts("竜巻注意情報 発表状況") } cols = ['発表日時', '解除日時', '対象地域', '件名', '補足'] opts = { :caption => ["竜巻注意情報 発表状況(", TatutyuLister.jihun(@curtime), '更新)'].join } @html.table(cols, opts) { @db.each {|row| @html.tag('tr') { rtime = TatutyuLister.jihun(row['rtime']) @html.tag('td') { @html.puts(rtime) } if row['vtime'] >= @curtime then vtime = TatutyuLister.jihun(row['vtime']) else vtime = '(解除済み)' end @html.tag('td') { @html.puts(vtime) } @html.tag('td', 'data-areacode'=>row['ac']) { @html.puts(row['an']) } mokugeki = !(row['mok'].to_i.zero?) opts = {} opts['class'] = 'level5' if mokugeki title = [row['tl'], '第', row['ser'], '号'].join @html.tag('td', opts) { @html.tag('a', 'href'=>row['src'], 'title'=>row['txt']) { @html.puts(title) } } mok = (mokugeki ? '【目撃情報あり】' : '') @html.tag('td', opts) { @html.puts(mok) } } } } end
run()
click to toggle source
# File makelist.rb, line 103 def run yomikomi buildpage File.open(@outfnam, 'w') {|outfile| @html.write(outfile) } end
yomikomi()
click to toggle source
# File makelist.rb, line 37 def yomikomi File.open(@infnam, 'r') { |infile| infile.each_line {|line| row = {} line.chomp.split(/\t/).each {|cell| key, val = cell.split(/:/, 2) val = Time.parse(val) if /time$/ =~ key row[key] = val } # 試験電文を排除 if row['st'] != '通常' $stderr.puts "reject #{row['rtime']} st=#{row['st']}" if $VERBOSE next end # 未来の電文を排除 if row['rtime'] > @curtime $stderr.puts "reject future #{row['rtime']}" if $VERBOSE next end # store message @db.push row } } @db.sort_by! {|row| row['rtime'] } @db.reverse! $stderr.puts "#{@db.size} lines loaded" if $VERBOSE end