class ArticleJSON::Import::GoogleDoc::HTML::EmbeddedTweetParser
Public Class Methods
url_regexp()
click to toggle source
Regular expression to check if a given string is a Twitter URL Also used to extract the ID from the URL. @return [Regexp]
# File lib/article_json/import/google_doc/html/embedded_tweet_parser.rb, line 23 def url_regexp %r{ ^\S* # all protocols & sub domains twitter\.com/ # domain (?<handle>[^#/]+) # twitter handle (?:\#|/status/|/statuses/) # optional path or hash char (?<id>\d+) # numeric tweet id }xi end
Public Instance Methods
embed_id()
click to toggle source
Extract the tweet ID (including the handle) from an URL @return [String]
# File lib/article_json/import/google_doc/html/embedded_tweet_parser.rb, line 14 def embed_id match = @node.inner_text.strip.match(self.class.url_regexp) "#{match[:handle]}/#{match[:id]}" if match end
embed_type()
click to toggle source
The type of this embedded element @return [Symbol]
# File lib/article_json/import/google_doc/html/embedded_tweet_parser.rb, line 8 def embed_type :tweet end