lib/gendered/guesser.rb in gendered-0.0.3 vs lib/gendered/guesser.rb in gendered-0.0.4

- old
+ new

@@ -11,25 +11,25 @@ def guess! response = HTTP.get(url) case response.code when 200 - @names = JSON.parse(response.body).collect do |guess| - name = names.find { |n| n.to_s == guess["name"] } - if name.is_a?(String) - name = Name.new(guess["name"]) - end + guesses = JSON.parse(response.body) - name.tap do |n| - if guess["gender"] - n.gender = guess["gender"].to_sym - n.probability = guess["probability"] - n.sample_size = guess["count"] - end + names.collect do |name| + name = Name.new(name) if name.is_a?(String) + + guess = guesses.find { |g| g["name"] == name.value } + + if guess["gender"] + name.gender = guess["gender"].to_sym + name.probability = guess["probability"] + name.sample_size = guess["count"] end + + name end - self.names end end def url url = "http://api.genderize.io/?"