Class: HtmlCssToImage::Data::Image

Inherits:
Object
  • Object
show all
Defined in:
lib/html_css_to_image/data/image.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(url:) ⇒ Image

Returns a new instance of Image.



14
15
16
17
18
19
20
21
# File 'lib/html_css_to_image/data/image.rb', line 14

def initialize(url:)
  url = URI(url)

  raise ArgumentError.new "Not https" unless url.scheme == HtmlCssToImage::API_SCHEME
  raise ArgumentError.new "Not HCTI API" unless url.host == HtmlCssToImage::API_HOST

  @url = url
end

Instance Attribute Details

#urlObject

Returns the value of attribute url.



6
7
8
# File 'lib/html_css_to_image/data/image.rb', line 6

def url
  @url
end

Class Method Details

.from(data) ⇒ Object



8
9
10
11
12
# File 'lib/html_css_to_image/data/image.rb', line 8

def self.from(data)
  raise ArgumentError.new "Key :url does not exist" unless data.key?(:url)

  Image.new(url: data[:url])
end

Instance Method Details

#idObject



23
24
25
26
27
28
# File 'lib/html_css_to_image/data/image.rb', line 23

def id
  url = @url.to_s
  i   = url.rindex('/') + 1

  url[i..-1]
end