Class: ArticleJSON::Import::GoogleDoc::HTML::EmbeddedTweetParser

Inherits:
EmbeddedParser
  • Object
show all
Defined in:
lib/article_json/import/google_doc/html/embedded_tweet_parser.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from EmbeddedParser

build, #element, #initialize, matches?, supported?, #tags

Methods included from Shared::Caption

#caption

Constructor Details

This class inherits a constructor from ArticleJSON::Import::GoogleDoc::HTML::EmbeddedParser

Class Method Details

.url_regexpRegexp

Regular expression to check if a given string is a Twitter URL Also used to extract the ID from the URL.

Returns:

  • (Regexp)


23
24
25
26
27
28
29
30
31
# 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

Instance Method Details

#embed_idString

Extract the tweet ID (including the handle) from an URL

Returns:

  • (String)


14
15
16
17
# 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_typeSymbol

The type of this embedded element

Returns:

  • (Symbol)


8
9
10
# File 'lib/article_json/import/google_doc/html/embedded_tweet_parser.rb', line 8

def embed_type
  :tweet
end