本日の天気予報を取得するクラス 修正

get_xml() でタイムアウトした場合、例外では無く '' を返した方が良さそうなので以下のように変更しました。

  def get_xml(pref_code)
    begin
      conn = Net::HTTP.new("www.drk7.jp")
      conn.open_timeout = 3
      conn.read_timeout = 3
      res, = conn.get("/weather/xml/#{pref_code}.xml")
      @xml = res.body
   rescue Timeout::Error
      @xml = ''
   end
    @xml
  end