Class: Pollock::Image
- Inherits:
-
Object
- Object
- Pollock::Image
- Defined in:
- lib/pollock/image.rb
Constant Summary collapse
- DEFAULT_COLOUR =
"#CCCCCC"
- FONT =
"georgia"
Instance Attribute Summary collapse
-
#colour ⇒ Object
Returns the value of attribute colour.
-
#format ⇒ Object
Returns the value of attribute format.
-
#height ⇒ Object
Returns the value of attribute height.
-
#text ⇒ Object
Returns the value of attribute text.
-
#width ⇒ Object
Returns the value of attribute width.
Instance Method Summary collapse
- #file_name ⇒ Object
-
#initialize(args = {}) ⇒ Image
constructor
A new instance of Image.
- #save(dir) ⇒ Object
- #text_colour ⇒ Object
Constructor Details
#initialize(args = {}) ⇒ Image
Returns a new instance of Image.
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
#colour ⇒ Object
Returns the value of attribute colour.
8 9 10 |
# File 'lib/pollock/image.rb', line 8 def colour @colour end |
#format ⇒ Object
Returns the value of attribute format.
8 9 10 |
# File 'lib/pollock/image.rb', line 8 def format @format end |
#height ⇒ Object
Returns the value of attribute height.
8 9 10 |
# File 'lib/pollock/image.rb', line 8 def height @height end |
#text ⇒ Object
Returns the value of attribute text.
8 9 10 |
# File 'lib/pollock/image.rb', line 8 def text @text end |
#width ⇒ Object
Returns the value of attribute width.
8 9 10 |
# File 'lib/pollock/image.rb', line 8 def width @width end |
Instance Method Details
#file_name ⇒ Object
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_colour ⇒ Object
40 41 42 |
# File 'lib/pollock/image.rb', line 40 def text_colour "#CC0000" end |