diff options
author | Rhenium <rhenium@rhe.jp> | 2014-01-20 17:08:34 +0900 |
---|---|---|
committer | Rhenium <rhenium@rhe.jp> | 2014-01-20 17:08:34 +0900 |
commit | e070c2808fc4b969e81bf0f8d6db5c1129e41b5a (patch) | |
tree | cf1724f55edf8cd37cb613feba81ade2344e912b /app | |
parent | 9c200d7edc7d02c8c6426e266a86e34d3cda0856 (diff) | |
download | aclog-e070c2808fc4b969e81bf0f8d6db5c1129e41b5a.tar.gz |
fix Tweet.extract_entities
Diffstat (limited to 'app')
-rw-r--r-- | app/models/tweet.rb | 13 |
1 files changed, 5 insertions, 8 deletions
diff --git a/app/models/tweet.rb b/app/models/tweet.rb index b400c74..582ef7b 100644 --- a/app/models/tweet.rb +++ b/app/models/tweet.rb @@ -106,18 +106,15 @@ class Tweet < ActiveRecord::Base end private + # replace t.co with expanded_url def self.extract_entities(json) - entity_values = json[:entities].values.sort_by {|v| v[:indices].first }.flatten + entity_values = json[:entities].values.flatten.sort_by {|v| v[:indices].first } + entity_values.select! {|e| e[:url] } result = "" last_index = entity_values.inject(0) do |last_index, entity| - result << json[:text][last_index...entity["indices"].first] - if entity.key?(:url) - result << entity[:expanded_url] - else - result << entity[:text] - end - + result << json[:text][last_index...entity[:indices].first] + result << entity[:expanded_url] entity[:indices].last end result << json[:text][last_index..-1] |