Watson1978
7/1/2012 - 9:48 PM

macruby reject bugs tweets

macruby reject bugs tweets

#!/usr/bin/env macruby -wKU
framework 'Foundation'

## first example reject works great
new_array = ["test", "test 1", "Test 2", "Test 3", 10].reject {|test| test.is_a?(Fixnum) }

p new_array

## second example it still showing tweets with iso_language_code == en

twitter_search = NSURL.URLWithString("http://search.twitter.com/search.json?q=@rubymotion&rpp=100")
  
data = NSData.dataWithContentsOfURL(twitter_search)
opts = NSJSONReadingMutableContainers | NSJSONWritingPrettyPrinted
json = NSJSONSerialization.JSONObjectWithData(data, options:opts, error:nil)

tweets = json[:results]
tweets = Array.new(tweets)
results = tweets.select { |tweet| tweet.is_a?(Hash) }
                .reject { |tweet| tweet[:iso_language_code] == "en" }
                .map    { |tweet|  "%<iso_language_code>s - %<from_user_name>s : %<text>s" % tweet }
puts results