Class: LinkPreview::ExternalImage

Inherits:
ExternalResource show all
Defined in:
lib/link_preview/external_image.rb

Direct Known Subclasses

ExternalFavicon

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from ExternalResource

#find_value

Constructor Details

#initialize(uri, image_path) ⇒ ExternalImage

Returns a new instance of ExternalImage.



11
12
13
14
15
16
# File 'lib/link_preview/external_image.rb', line 11

def initialize(uri, image_path)
  @uri        = uri
  @image_path = image_path

  super(path)
end

Instance Attribute Details

#image_pathObject (readonly)

Returns the value of attribute image_path.



3
4
5
# File 'lib/link_preview/external_image.rb', line 3

def image_path
  @image_path
end

Class Method Details

.parse(uri, document) ⇒ Object



5
6
7
8
9
# File 'lib/link_preview/external_image.rb', line 5

def self.parse(uri, document)
  document.css("img").collect { |image|
    self.new(uri, image.attributes['src'].value) if image.attributes['src'].present?
  }
end

Instance Method Details

#pathObject



18
19
20
21
22
23
24
25
26
# File 'lib/link_preview/external_image.rb', line 18

def path
  return '' if image_path.blank?

  if URI.regexp !~ image_path
    "#{File.join(@uri, image_path)}"
  else
    image_path
  end
end