Class: Pollock::Image

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

Constant Summary collapse

DEFAULT_COLOUR =
"#CCCCCC"
FONT =
"georgia"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args = {}) ⇒ Image

Returns a new instance of Image.

Raises:

  • (ArgumentError)


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

def initialize(args={})
  args = build_args_from_string(args) if args.is_a? String
  raise ArgumentError.new("Image requires at least a size :height=>300") unless (args[:height]||args[:width]).to_i >0
  self.height = (args[:height]||args[:width]).to_i
  self.width = (args[:width]||args[:height]).to_i
  self.text = args[:text]
  self.colour = args[:colour]
  self.format = args[:format]||'jpg'
end

Instance Attribute Details

#colourObject

Returns the value of attribute colour.



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

def colour
  @colour
end

#formatObject

Returns the value of attribute format.



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

def format
  @format
end

#heightObject

Returns the value of attribute height.



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

def height
  @height
end

#textObject

Returns the value of attribute text.



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

def text
  @text
end

#widthObject

Returns the value of attribute width.



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

def width
  @width
end

Instance Method Details

#file_nameObject



44
45
46
47
48
49
# File 'lib/pollock/image.rb', line 44

def file_name
  parts = [default_text]
  parts << ((text == default_text) ? '' : text.downcase.gsub(/[^a-z]/, '_'))
  parts << ((colour == DEFAULT_COLOUR) ? '' : colour.gsub("#", ''))
  parts.join('-').gsub(/-+$/, '')+"."+format
end

#save(dir) ⇒ Object



51
52
53
54
55
# File 'lib/pollock/image.rb', line 51

def save(dir)
  path = File.join(dir, file_name)
  image.write(path)
  path
end

#text_colourObject



40
41
42
# File 'lib/pollock/image.rb', line 40

def text_colour
  "#CC0000"
end