Skip to content

Commit

Permalink
Method to see if tweet has loaded entities
Browse files Browse the repository at this point in the history
  • Loading branch information
tedkulp committed Aug 20, 2012
1 parent d07cbf2 commit 43221b1
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions lib/twitter/tweet.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 43221b1

Please sign in to comment.