Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Apr 27th, 2012  |  syntax: None  |  size: 1.59 KB  |  hits: 16  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. I am running this code from the govkit gem
  2.  
  3. #govkit / lib / gov_kit / open_congress / bill.rb
  4.  
  5.      def self.bills_in_the_news_this_week
  6.         url = construct_url("bills_in_the_news_this_week", {})
  7.         if (result = make_call(url))
  8.           bills = parse_results(result)
  9.           return bills
  10.         else
  11.           nil
  12.         end      
  13.       end
  14.  
  15. def self.parse_results(result)
  16.      
  17.         bills = []
  18.         result["bills"].each do |bill|
  19.        
  20.           these_recent_blogs = bill["recent_blogs"]
  21.           blogs = []
  22.  
  23.           if these_recent_blogs
  24.             these_recent_blogs.each do |trb|
  25.               blogs << BlogPost.new(trb)
  26.             end
  27.           end
  28.  
  29.           bill["recent_blogs"] = blogs
  30.  
  31.  
  32.           these_recent_news = bill["recent_news"]
  33.           news = []
  34.           if these_recent_news
  35.             these_recent_news.each do |trb|
  36.               news << NewsPost.new(trb)
  37.             end
  38.           end
  39.  
  40.           bill["recent_news"] = news
  41.  
  42.           these_co_sponsors = bill["co_sponsors"]
  43.           co_sponsors = []
  44.           if these_co_sponsors
  45.             these_co_sponsors.each do |tcs|
  46.               co_sponsors << Person.new(tcs)
  47.             end
  48.           end
  49.  
  50.           bill["co_sponsors"] = co_sponsors
  51.  
  52.        
  53.           bill["sponsor"] = Person.new(bill["sponsor"]) if bill["sponsor"]
  54.        
  55.        
  56.           bills << Bill.new(bill)
  57.         end
  58.         bills
  59.       end
  60.  
  61. getting a good result that has an array of bills, each bill is a Hash (27 element(s))
  62.  
  63. but parse results turns result into an array of  #<GovKit::OpenCongress::Bill:0x000001055496a0> with no values.