diff options
author | Rhenium <rhenium@rhe.jp> | 2014-01-20 13:02:15 +0900 |
---|---|---|
committer | Rhenium <rhenium@rhe.jp> | 2014-01-20 13:02:15 +0900 |
commit | d282b7ef38f3cf42e8d9e4fd104228d0bf95f856 (patch) | |
tree | c182289010ed08e16fe8ebdeb25d219999ec2dea /app/models/tweet.rb | |
parent | 2ad52ebb033394cb721f55a90af977adfb596a16 (diff) | |
download | aclog-d282b7ef38f3cf42e8d9e4fd104228d0bf95f856.tar.gz |
update models
Diffstat (limited to 'app/models/tweet.rb')
-rw-r--r-- | app/models/tweet.rb | 22 |
1 files changed, 11 insertions, 11 deletions
diff --git a/app/models/tweet.rb b/app/models/tweet.rb index 3e5017b..b400c74 100644 --- a/app/models/tweet.rb +++ b/app/models/tweet.rb @@ -42,18 +42,18 @@ class Tweet < ActiveRecord::Base end end - def self.from_json(msg) - find_by(id: msg[:id]) || begin - user = User.from_json(msg[:user]) - create!(id: msg[:id], - text: extract_entities(msg), - source: msg[:source], - tweeted_at: msg[:created_at], - in_reply_to_id: msg[:in_reply_to_status_id], + def self.from_json(json) + find_by(id: json[:id]) || begin + user = User.from_json(json[:user]) + create!(id: json[:id], + text: extract_entities(json), + source: json[:source], + tweeted_at: json[:created_at], + in_reply_to_id: json[:in_reply_to_status_id], user: user) end rescue ActiveRecord::RecordNotUnique - logger.debug("Duplicate Tweet: #{msg[:id]}") + logger.debug("Duplicate Tweet: #{json[:id]}") rescue => e logger.error("Unknown error while inserting tweet: #{e.class}: #{e.message}/#{e.backtrace.join("\n")}") end @@ -78,7 +78,7 @@ class Tweet < ActiveRecord::Base end parse_condition = ->(scoped, token) do - p positive = !token.slice!(/^[-!]/) + positive = !token.slice!(/^[-!]/) where_args = case token when /^(?:user|from):([A-Za-z0-9_]{1,20})$/ @@ -107,7 +107,7 @@ class Tweet < ActiveRecord::Base private def self.extract_entities(json) - entity_values = json[:entities].values.sort_by {|v| v[:indices].first } + entity_values = json[:entities].values.sort_by {|v| v[:indices].first }.flatten result = "" last_index = entity_values.inject(0) do |last_index, entity| |