Class: ArticleJSON::Import::GoogleDoc::HTML::ImageParser
- Inherits:
-
Object
- Object
- ArticleJSON::Import::GoogleDoc::HTML::ImageParser
- Includes:
- Shared::Caption, Shared::Float
- Defined in:
- lib/article_json/import/google_doc/html/image_parser.rb
Instance Method Summary collapse
-
#alt ⇒ String
The value of the image’s ‘alt` attribute.
- #element ⇒ ArticleJSON::Elements::Image
-
#float ⇒ Symbol
Check if the image is floating (left, right or not at all).
-
#href ⇒ String
Extracts an href from the tag [image-link-to: url]) if present in the caption node.
-
#image_node ⇒ Nokogiri::HTML::Node
The node of the actual image.
-
#initialize(node:, caption_node:, css_analyzer:) ⇒ ImageParser
constructor
A new instance of ImageParser.
-
#source_url ⇒ String
The value of the image’s ‘src` attribute.
Methods included from Shared::Caption
Constructor Details
#initialize(node:, caption_node:, css_analyzer:) ⇒ ImageParser
Returns a new instance of ImageParser.
12 13 14 15 16 17 18 19 20 |
# File 'lib/article_json/import/google_doc/html/image_parser.rb', line 12 def initialize(node:, caption_node:, css_analyzer:) @node = node @caption_node = @href = href @css_analyzer = css_analyzer # Main node indicates the floating behavior @float_node = @node end |
Instance Method Details
#alt ⇒ String
The value of the image’s ‘alt` attribute
24 25 26 27 28 |
# File 'lib/article_json/import/google_doc/html/image_parser.rb', line 24 def alt return '' if image_url? image_node.attribute('alt')&.value || '' end |
#element ⇒ ArticleJSON::Elements::Image
64 65 66 67 68 69 70 71 72 |
# File 'lib/article_json/import/google_doc/html/image_parser.rb', line 64 def element ArticleJSON::Elements::Image.new( source_url: source_url, float: float, caption: , href: @href, alt: alt ) end |
#float ⇒ Symbol
Check if the image is floating (left, right or not at all)
48 49 50 |
# File 'lib/article_json/import/google_doc/html/image_parser.rb', line 48 def float super if image_url? || floatable_size? end |
#href ⇒ String
Extracts an href from the tag [image-link-to: url]) if present in the caption node.
55 56 57 58 59 60 61 |
# File 'lib/article_json/import/google_doc/html/image_parser.rb', line 55 def href return if @caption_node.nil? match = @caption_node.content.strip.match(href_regexp) return if match.nil? remove_image_link_tag match[:url] end |
#image_node ⇒ Nokogiri::HTML::Node
The node of the actual image
40 41 42 43 44 |
# File 'lib/article_json/import/google_doc/html/image_parser.rb', line 40 def image_node return @image_node if defined? @image_node @image_node = @node.xpath('.//img').first end |
#source_url ⇒ String
The value of the image’s ‘src` attribute
32 33 34 35 36 |
# File 'lib/article_json/import/google_doc/html/image_parser.rb', line 32 def source_url return @node.inner_text.strip if image_url? image_node.attribute('src').value end |