#!/usr/bin/ruby require 'selsurf.rb' class JpReport < SelSurf WINDMAP = { 0 => '風弱く', 1 => '北の風、', 2 => 'ホク北東の風、', 3 => 'ホク北東の風、', 4 => '北東の風、', 5 => '北東の風、', 6 => 'トウ北東の風、', 7 => 'トウ北東の風、', 8 => '東の風、', 9 => '東の風、', 10 => '東の風、', 11 => 'トウ南東の風、', 12 => 'トウ南東の風、', 13 => '南東の風、', 14 => '南東の風、', 15 => 'ナン南東の風、', 16 => 'ナン南東の風、', 17 => '南の風、', 18 => '南の風、', 19 => '南の風、', 20 => 'ナン南西の風、', 21 => 'ナン南西の風、', 22 => '南西の風、', 23 => '南西の風、', 24 => 'セイ南西の風、', 25 => 'セイ南西の風、', 26 => '西の風、', 27 => '西の風、', 28 => '西の風、', 29 => 'セイ北西の風、', 30 => 'セイ北西の風、', 31 => '北西の風、', 32 => '北西の風、', 33 => 'ホク北西の風、', 34 => 'ホク北西の風、', 35 => '北の風、', 36 => '北の風、' } def convert ent, dcd avail = {} ent[:ID] = dcd['@ID'] if Numeric === (v = dcd['TTT']) then ent[:T] = ((v.to_f + 5) * 0.1).floor.to_s.sub(/^-/, '氷点下') + "度" avail['T'] = true end ent[:T] = "気温不明" unless ent[:T] if Numeric === (v = dcd['P.4']) then ent[:P] = ((v.to_f + 5) * 0.1).floor.to_s + 'ヘクトパスカル' avail['P'] = true end ent[:P] = "気圧不明" unless ent[:P] ent[:d] = WINDMAP[dcd['dd']] ent[:d] = '風向不明、' unless ent[:d] ent[:f] = case v = dcd['ff'] when 0 then '' when Numeric then avail['d'] = true case dcd['iw'] when 3..4 then '風力' + (((v + 0.33) * 0.615364) ** (2.0 / 3.0) + 0.5).floor.to_s else '風力' + ((v * 1.196172248) ** (2.0 / 3.0) + 0.5).floor.to_s end end ent[:f] = '風力不明' unless ent[:f] w = case dcd['ww'] when 5 then dcd['VV'].to_i <= 19 ? '煙霧' : nil when 6 then dcd['N'] == 9 ? 'ちり煙霧' : nil when 17, 91..96, 98 then '雷' when 30..35 then '砂塵あらし' when 36..39 then '地吹雪' when 42..49 then '霧' when 50..57 then '霧雨' when 58..63, 66..67 then '雨' when 64..65, 82 then '雨つよし' when 68..69, 83..84 then 'みぞれ' when 70..73, 77..78 then 'みぞれ' when 74..75 then '雪つよし' when 79, 87..89 then 'あられ' when 80..81 then 'にわか雨' when 85..86 then 'にわか雪' when 89 then 'ひょう' when 97, 99 then '雷つよし' else nil end unless w w = case dcd['wawa'] when 94..96 then '雷つよし' when 90..93 then '雷' when 89 then dcd['TTT'].to_i < 0 ? '雪' : 'ひょう' when 73, 87 then '雪つよし' when 74..76 then 'あられ' when 45..46, 70..77, 85..86 then '雪' # overlaps when 63, 66, 83..84 then '雨つよし' when 43..48, 57..58, 60..65, 81..82 then '雨' # overlaps when 50..56 then '霧雨' when 30, 32..35 then '霧' when 27..29 then '地吹雪' when 4..5 then dcd['VV'].to_i <= 19 ? '煙霧' : nil else nil end end unless w w = case dcd['N'] when 0..1 then '快晴' when 2..6 then '晴れ' when 7..8 then '曇り' else nil end if w case dcd['ix'] when 3, 6 then w = nil end end end unless w w = case dcd['RRR'] when 1..989 then '降水あり' end end avail['w'] = true if w w = "天気不明" unless w case dcd['ppp'] when 20..999 then w = [w, '気圧上昇'].compact.join('、') when (-999)..(-20) then w = [w, '気圧降下'].compact.join('、') end ent[:w] = w ent[:miss] = false unless avail.empty? end def slalo lat, lon slat = (lat >= 0 ? "北緯#{lat}度" : "南緯#{-lat}度") slon = (lon >= 0 ? "東経#{lon}度" : "西経#{-lon}度") [slat, slon].join('、') end def report puts <