Module: TweetSanitizer
- Defined in:
- lib/tweet_sanitizer.rb,
lib/tweet_sanitizer/version.rb,
lib/tweet_sanitizer/twitter_extension.rb
Defined Under Namespace
Modules: TwitterExtension
Constant Summary
collapse
- VERSION =
"0.1.0"
Class Method Summary
collapse
Class Method Details
.expand_urls_text(tweet) ⇒ String
17
18
19
20
21
22
23
24
25
26
|
# File 'lib/tweet_sanitizer.rb', line 17
def self.expand_urls_text()
text = ()
return text unless .uris?
.uris.reverse.each_with_object(text.dup) do |uri, expanded|
pos1 = uri.indices[0]
pos2 = uri.indices[1]
expanded[pos1, pos2-pos1] = uri.expanded_url
end
end
|
39
40
41
42
43
44
45
46
|
# File 'lib/tweet_sanitizer.rb', line 39
def self.(, text)
return text unless .media?
.media.each_with_object(text.dup) do |media, t|
t.gsub!(media.url, "")
t.strip!
end
end
|
.sanitize(tweet) ⇒ String
8
9
10
11
12
13
|
# File 'lib/tweet_sanitizer.rb', line 8
def self.sanitize()
text = expand_urls_text()
text = (, text)
text = CGI.unescapeHTML(text)
text
end
|
Returns ‘full_text` attribute if exist.
30
31
32
33
34
|
# File 'lib/tweet_sanitizer.rb', line 30
def self.()
.attrs[:full_text] || .text
end
|