Class: Ficon::Image

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(url, tile_color = nil) ⇒ Image

Returns a new instance of Image.



8
9
10
11
12
13
14
15
16
# File 'lib/ficon/image.rb', line 8

def initialize(url, tile_color = nil)
  @url = url
  @tile_color = tile_color
  c = Cache.new(@url)
  cached_size = Cache.new(url).data
  @size = cached_size ? JSON.parse(cached_size) : FastImage.size(url)
  c.data = @size.to_json if @size
  @area = @size&.inject(&:*) || 0
end

Instance Attribute Details

#areaObject (readonly)

Returns the value of attribute area.



7
8
9
# File 'lib/ficon/image.rb', line 7

def area
  @area
end

#sizeObject (readonly)

Returns the value of attribute size.



7
8
9
# File 'lib/ficon/image.rb', line 7

def size
  @size
end

#tile_colorObject (readonly)

Returns the value of attribute tile_color.



7
8
9
# File 'lib/ficon/image.rb', line 7

def tile_color
  @tile_color
end

#urlObject (readonly)

Returns the value of attribute url.



7
8
9
# File 'lib/ficon/image.rb', line 7

def url
  @url
end

Instance Method Details

#to_sObject



18
19
20
21
22
# File 'lib/ficon/image.rb', line 18

def to_s
  result = @url.to_s + " (#{@size})"
  result += " [#{@tile_color}]" if @tile_color
  result
end