Class: ArticleJSON::Import::GoogleDoc::HTML::EmbeddedParser
- Inherits:
-
Object
- Object
- ArticleJSON::Import::GoogleDoc::HTML::EmbeddedParser
- Includes:
- Shared::Caption
- Defined in:
- lib/article_json/import/google_doc/html/embedded_parser.rb
Direct Known Subclasses
EmbeddedFacebookVideoParser, EmbeddedSlideshareParser, EmbeddedSoundcloudParser, EmbeddedTweetParser, EmbeddedVimeoVideoParser, EmbeddedYoutubeVideoParser
Class Method Summary collapse
-
.build(node:, caption_node:, css_analyzer:) ⇒ ArticleJSON::Elements::Embed
Build a embedded element based on the node’s content.
-
.matches?(text) ⇒ Boolean
Check if a given string is a Youtube embedding.
-
.supported?(node) ⇒ Boolean
Check if a node contains a supported embedded element.
-
.url_regexp ⇒ Regexp
Regular expression to check if node content is embeddable element Is also used to extract the ID from the URL.
Instance Method Summary collapse
-
#element ⇒ ArticleJSON::Elements::Embed
The embedded element.
-
#embed_id ⇒ String
Extract the video ID from an URL.
-
#embed_type ⇒ Symbol
The type of this embedded element To be implemented by sub classes!.
-
#initialize(node:, caption_node:, css_analyzer:) ⇒ EmbeddedParser
constructor
A new instance of EmbeddedParser.
-
#tags ⇒ Array[Symbol]
Extract any potential tags, specified in brackets after the URL.
Methods included from Shared::Caption
Constructor Details
#initialize(node:, caption_node:, css_analyzer:) ⇒ EmbeddedParser
Returns a new instance of EmbeddedParser.
11 12 13 14 15 |
# File 'lib/article_json/import/google_doc/html/embedded_parser.rb', line 11 def initialize(node:, caption_node:, css_analyzer:) @node = node @caption_node = caption_node @css_analyzer = css_analyzer end |
Class Method Details
.build(node:, caption_node:, css_analyzer:) ⇒ ArticleJSON::Elements::Embed
Build a embedded element based on the node’s content
69 70 71 72 73 74 75 76 77 |
# File 'lib/article_json/import/google_doc/html/embedded_parser.rb', line 69 def build(node:, caption_node:, css_analyzer:) find_parser(node.inner_text) &.new( node: node, caption_node: caption_node, css_analyzer: css_analyzer ) &.element end |
.matches?(text) ⇒ Boolean
Check if a given string is a Youtube embedding
53 54 55 |
# File 'lib/article_json/import/google_doc/html/embedded_parser.rb', line 53 def matches?(text) !!(url_regexp =~ text) end |
.supported?(node) ⇒ Boolean
Check if a node contains a supported embedded element
82 83 84 |
# File 'lib/article_json/import/google_doc/html/embedded_parser.rb', line 82 def supported?(node) !find_parser(node.inner_text).nil? end |
.url_regexp ⇒ Regexp
Regular expression to check if node content is embeddable element Is also used to extract the ID from the URL.
60 61 62 |
# File 'lib/article_json/import/google_doc/html/embedded_parser.rb', line 60 def url_regexp raise NotImplementedError end |
Instance Method Details
#element ⇒ ArticleJSON::Elements::Embed
The embedded element
40 41 42 43 44 45 46 47 |
# File 'lib/article_json/import/google_doc/html/embedded_parser.rb', line 40 def element ArticleJSON::Elements::Embed.new( embed_type: , embed_id: , tags: , caption: caption ) end |
#embed_id ⇒ String
Extract the video ID from an URL
19 20 21 22 |
# File 'lib/article_json/import/google_doc/html/embedded_parser.rb', line 19 def match = @node.inner_text.strip.match(self.class.url_regexp) match[:id] if match end |
#embed_type ⇒ Symbol
The type of this embedded element To be implemented by sub classes!
27 28 29 |
# File 'lib/article_json/import/google_doc/html/embedded_parser.rb', line 27 def raise NotImplementedError end |
#tags ⇒ Array[Symbol]
Extract any potential tags, specified in brackets after the URL
33 34 35 36 |
# File 'lib/article_json/import/google_doc/html/embedded_parser.rb', line 33 def match = /(.*?)[\s\u00A0]+\[(?<tags>.*)\]/.match(@node.inner_text) (match ? match[:tags] : '').split(' ') end |