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



45
46
47
# File 'lib/link_thumbnailer/scrapers/opengraph/image.rb', line 45

def attribute
  'og:image'
end

#heightObject



57
58
59
# File 'lib/link_thumbnailer/scrapers/opengraph/image.rb', line 57

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

#modelObject



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

def model
  nodes.map do |n|
    uri =  LinkThumbnailer::URI.new(n.attributes['content'])
    modelize(n, uri.to_s) if uri.valid?
  end.compact
end

#model_classObject



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

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

#modelize(node, text = nil) ⇒ Object



32
33
34
# File 'lib/link_thumbnailer/scrapers/opengraph/image.rb', line 32

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

#nodesObject



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

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

#sizeObject



49
50
51
# File 'lib/link_thumbnailer/scrapers/opengraph/image.rb', line 49

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

#valueObject



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

def value
  model
end

#widthObject



53
54
55
# File 'lib/link_thumbnailer/scrapers/opengraph/image.rb', line 53

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