Last active
August 29, 2015 14:25
-
-
Save yswallow/98bd0e72e1c4a4cbc705 to your computer and use it in GitHub Desktop.
Twitter gemのTweetにto_htmlメソッドを足す
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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