Class: ArtsyDev::Handler

Inherits:
Object
  • Object
show all
Defined in:
lib/artsy/devel/handler.rb

Overview

parent class as a namespace

Class Method Summary collapse

Class Method Details

.rgbOutOfRange(mode, r, g, b) ⇒ Object

subclass: contains some preset argumenterror cases



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/artsy/devel/handler.rb', line 5

def self.rgbOutOfRange(mode, r, g, b)
  # HACK: Change mode in the script to change how your artsy install deals with errors.
  if mode == "strict"
    # strict: raise an argument error exception without catching
    limit = 255 # set limit
    unless r <= limit and r >= 0
      # fail if r exceeds limit or if lower than 0.
      raise ArgumentError.new "'r' value out of range. Must be between 0-255 (you entered #{r})."
    end
    unless g <= limit and g >= 0
      # fail for green
      raise ArgumentError.new "'g' value out of range. Must be between 0-255 (you entered #{g})."
    end
    unless b <= limit and b >= 0
      # fail for blue
      raise ArgumentError.new "'b' value out of range. Must be between 0-255 (you entered #{b})."
    end
  elsif mode == "chill"
    # chill: Print a warning message to stderr, but don't raise exception.
    limit = 255
    unless r <= limit and r >= 0
      # warn for red
      STDERR.puts "WARNING: red value out of range... (#{r})"
    end
    unless g <= limit and g >= 0
      # warn for green
      STDERR.puts "WARNING: green value out of range... (#{g})"
    end
    unless b <= limit and b >= 0
      # warn for blue
      STDERR.puts "WARNING: blue value out of range... (#{b})"
    end
  end
end