Skip to content

Instantly share code, notes, and snippets.

@yswallow
Last active August 29, 2015 14:25
Show Gist options
  • Select an option

  • Save yswallow/98bd0e72e1c4a4cbc705 to your computer and use it in GitHub Desktop.

Select an option

Save yswallow/98bd0e72e1c4a4cbc705 to your computer and use it in GitHub Desktop.
Twitter gemのTweetにto_htmlメソッドを足す
class Twitter::Tweet
def status_html
tweet = self.full_text.dup
urls = []
self.urls.each do |url_obj|
urls << { indices: url_obj.indices,
display_url: url_obj.display_url,
url: url_obj.expanded_url }
end
self.media.each do |media|
urls << { indices: media.indices,
display_url: media.display_url,
url: media.media_url }
end
urls.sort_by { |url_obj| url_obj[:indices][0] }
urls.reverse!
urls.each do |url_obj|
tweet[(url_obj[:indices][0])...(url_obj[:indices][1])] = "<a href='#{url_obj[:url]}'>#{url_obj[:display_url]}</a>"
end
return tweet
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment