From 43221b1d5fc1a3333a4718c79fd95f9ad42f143e Mon Sep 17 00:00:00 2001 From: Ted Kulp Date: Mon, 20 Aug 2012 08:06:06 -0400 Subject: [PATCH] Method to see if tweet has loaded entities --- lib/twitter/tweet.rb | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/lib/twitter/tweet.rb b/lib/twitter/tweet.rb index 4f830dd92..0051266a8 100644 --- a/lib/twitter/tweet.rb +++ b/lib/twitter/tweet.rb @@ -117,18 +117,22 @@ def user_mentions @user_mentions ||= entities(Twitter::Entity::UserMention, :user_mentions) end + def entities? + !@attrs[:entities].nil? + end + private # @param klass [Class] # @param method [Symbol] def entities(klass, method) - if @attrs[:entities].nil? - warn "#{Kernel.caller.first}: To get #{method.to_s.tr('_', ' ')}, you must pass `:include_entities => true` when requesting the #{self.class.name}." - [] - else + if entities? Array(@attrs[:entities][method.to_sym]).map do |user_mention| klass.fetch_or_new(user_mention) end + else + warn "#{Kernel.caller.first}: To get #{method.to_s.tr('_', ' ')}, you must pass `:include_entities => true` when requesting the #{self.class.name}." + [] end end