Get the hashtag using twitter gem

2019-09-07 07:18发布

问题:

I am using twitter gem to stream tweets in ruby. My code is

client.filter(:track => topics.join(",")) do |object|
  if(object.is_a?(Twitter::Entities))
  puts object.text if object.is_a?(Twitter::Tweet)
  puts object.created_at
  puts object.hashtags.to_s
  puts object.user.name
end
end

I need to fetch the hashtags in the tweet, if i use the above code I am getting the output as

 [#<Twitter::Entity::Hashtag:0x007ff23a06d4c8 @attrs={:text=>"coffee", :indices=>[20, 27]}>, #<Twitter::Entity::Hashtag:0x007ff23a06d450 @attrs={:text=>"mornings", :indices=>[28, 37]}>, #<Twitter::Entity::Hashtag:0x007ff23a06d428 @attrs={:text=>"cantstopmoving", :indices=>[38, 53]}>]

is there a way to fetch the individual hashtags

回答1:

object.hashtags.each do |p|
  puts "HashTags " +p.text.to_s
end