lib/weather_hacker/client.rb
# parse area table hash of response from Weather API
parse area table hash of response from Weather API
parse area table hash of response from Weather API
def parse_area_table(hash)
      @pref_by_city ||= {}
      @id_by_city   ||= {}
      hash["rss"]["channel"]["source"]["pref"].each do |pref|
        pref_name = canonical_pref(pref["title"])
        cities = [pref["city"]].flatten
        cities.each do |city|
          id    = city["id"].to_i
          title = city["title"]
          @id_by_city[title] = id
          @pref_by_city[title] = pref_name
        end
      end
    rescue
      raise ParseError, "Failed to parse area data from API"
    end
def parse_area_table ( hash ) @pref_by_city ||= { } @id_by_city ||= { } hash [ "rss" ] [ "channel" ] [ "source" ] [ "pref" ] . each do | pref | pref_name = canonical_pref ( pref [ "title" ] ) cities = [ pref [ "city" ] ] . flatten cities . each do | city | id = city [ "id" ] . to_i title = city [ "title" ] @id_by_city [ title ] = id @pref_by_city [ title ] = pref_name end end rescue raise ParseError , "Failed to parse area data from API" end
parse area table hash of response from Weather API
parse area table hash of response from Weather API
hash