Class: LooksGood::Image

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

Direct Known Subclasses

ImageFromElement, ImageFromFile

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(image, file_name) ⇒ Image

Returns a new instance of Image.



8
9
10
11
# File 'lib/looks_good/image.rb', line 8

def initialize image, file_name
  @file_name = file_name
  @image = image
end

Instance Attribute Details

#file_nameObject

Returns the value of attribute file_name.



4
5
6
# File 'lib/looks_good/image.rb', line 4

def file_name
  @file_name
end

#imageObject

Returns the value of attribute image.



4
5
6
# File 'lib/looks_good/image.rb', line 4

def image
  @image
end

#path(type = :reference) ⇒ Object

Returns the value of attribute path.



4
5
6
# File 'lib/looks_good/image.rb', line 4

def path
  @path
end

#typeObject (readonly)

Returns the value of attribute type.



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

def type
  @type
end

Instance Method Details

#exists?Boolean

Returns:

  • (Boolean)


20
21
22
# File 'lib/looks_good/image.rb', line 20

def exists?
  File.exists?(path)
end

#save(type = :reference) ⇒ Object



13
14
15
16
17
18
# File 'lib/looks_good/image.rb', line 13

def save(type = :reference)
  save_path = path(type)
  FileUtils::mkdir_p(File.dirname(save_path)) unless File.exists?(save_path)
  @image.write save_path
  save_path
end