Class: LinkThumbnailer::Scrapers::Opengraph::Image::Base

Inherits:
Base
  • Object
show all
Defined in:
lib/link_thumbnailer/scrapers/opengraph/image.rb

Overview

Handles ‘og:image` attributes.

Direct Known Subclasses

Url

Instance Attribute Summary

Attributes inherited from Base

#attribute_name, #config, #document, #website

Instance Method Summary collapse

Methods inherited from Base

#applicable?

Methods inherited from Base

#applicable?, #call, #initialize

Constructor Details

This class inherits a constructor from LinkThumbnailer::Scrapers::Base

Instance Method Details

#attributeObject



39
40
41
# File 'lib/link_thumbnailer/scrapers/opengraph/image.rb', line 39

def attribute
  'og:image'
end

#heightObject



51
52
53
# File 'lib/link_thumbnailer/scrapers/opengraph/image.rb', line 51

def height
  ::LinkThumbnailer::Scrapers::Opengraph::Image::Height.new(document).value
end

#modelObject



22
23
24
# File 'lib/link_thumbnailer/scrapers/opengraph/image.rb', line 22

def model
  nodes.map { |n| modelize(n, n.attributes['content'].to_s) }
end

#model_classObject



30
31
32
# File 'lib/link_thumbnailer/scrapers/opengraph/image.rb', line 30

def model_class
  ::LinkThumbnailer::Models::Image
end

#modelize(node, text = nil) ⇒ Object



26
27
28
# File 'lib/link_thumbnailer/scrapers/opengraph/image.rb', line 26

def modelize(node, text = nil)
  model_class.new(text, size)
end

#nodesObject



34
35
36
37
# File 'lib/link_thumbnailer/scrapers/opengraph/image.rb', line 34

def nodes
  nodes = meta_xpaths(attribute: attribute)
  nodes.empty? ? meta_xpaths(attribute: attribute, key: :name) : nodes
end

#sizeObject



43
44
45
# File 'lib/link_thumbnailer/scrapers/opengraph/image.rb', line 43

def size
  [width.to_i, height.to_i] if width && height
end

#valueObject



18
19
20
# File 'lib/link_thumbnailer/scrapers/opengraph/image.rb', line 18

def value
  model
end

#widthObject



47
48
49
# File 'lib/link_thumbnailer/scrapers/opengraph/image.rb', line 47

def width
  ::LinkThumbnailer::Scrapers::Opengraph::Image::Width.new(document).value
end