Class: LinkPreview::ExternalImage
- Inherits:
-
ExternalResource
- Object
- String
- ExternalResource
- LinkPreview::ExternalImage
- Defined in:
- lib/link_preview/external_image.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#image_path ⇒ Object
readonly
Returns the value of attribute image_path.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(uri, image_path) ⇒ ExternalImage
constructor
A new instance of ExternalImage.
- #path ⇒ Object
Methods inherited from ExternalResource
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_path ⇒ Object (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
#path ⇒ Object
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 |