Class: DummyImage::Image

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

Defined Under Namespace

Modules: ImageBuilder

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(arguments) ⇒ Image

Returns a new instance of Image.



10
11
12
# File 'lib/dummy_image/image.rb', line 10

def initialize arguments
  @arguments = arguments
end

Instance Attribute Details

#argumentsObject (readonly)

Returns the value of attribute arguments.



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

def arguments
  @arguments
end

Class Method Details

.find(arguments) ⇒ Object



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

def self.find(arguments)
  new(arguments).image
end

Instance Method Details

#bgcolorObject



30
31
32
# File 'lib/dummy_image/image.rb', line 30

def bgcolor
  arguments.bgcolor
end

#captionObject



49
50
51
# File 'lib/dummy_image/image.rb', line 49

def caption
  [width, height].join(" x ")
end

#create_image!Object



53
54
55
# File 'lib/dummy_image/image.rb', line 53

def create_image!
  ImageBuilder.build width, height, fgcolor, bgcolor, caption, file_path
end

#fgcolorObject



26
27
28
# File 'lib/dummy_image/image.rb', line 26

def fgcolor
  arguments.fgcolor
end

#file_pathObject



38
39
40
# File 'lib/dummy_image/image.rb', line 38

def file_path
  ["tmp", image_name].join "/"
end

#formatObject



34
35
36
# File 'lib/dummy_image/image.rb', line 34

def format
  arguments.format
end

#heightObject



22
23
24
# File 'lib/dummy_image/image.rb', line 22

def height
  arguments.height
end

#imageObject



42
43
44
45
46
47
# File 'lib/dummy_image/image.rb', line 42

def image
  unless File.exists? file_path
    create_image!
  end
  image_name
end

#image_nameObject



14
15
16
# File 'lib/dummy_image/image.rb', line 14

def image_name
  [width, height, fgcolor, bgcolor].join("_") + "." + format
end

#widthObject



18
19
20
# File 'lib/dummy_image/image.rb', line 18

def width
  arguments.width
end