Class: ColorPicker::Palette

Inherits:
Object
  • Object
show all
Defined in:
lib/color_picker/palette.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(palette_type = "complete_palette") ⇒ Palette



5
6
7
8
9
10
# File 'lib/color_picker/palette.rb', line 5

def initialize(palette_type="complete_palette")
  @range, @blue_color_range, @green_color_range, @red_color_range = []
			@max_number_of_colors=0
  @range_html = ""
  eval "#{palette_type}"
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(m, *args, &block) ⇒ Object



47
48
49
# File 'lib/color_picker/palette.rb', line 47

def method_missing(m, *args, &block)
  puts "There's no color palette type #{m} here -- please select strong colors color palette"
end

Instance Attribute Details

#blue_color_rangeObject (readonly)

Returns the value of attribute blue_color_range.



4
5
6
# File 'lib/color_picker/palette.rb', line 4

def blue_color_range
  @blue_color_range
end

#green_color_rangeObject (readonly)

Returns the value of attribute green_color_range.



4
5
6
# File 'lib/color_picker/palette.rb', line 4

def green_color_range
  @green_color_range
end

#max_number_of_colorsObject (readonly)

Returns the value of attribute max_number_of_colors.



3
4
5
# File 'lib/color_picker/palette.rb', line 3

def max_number_of_colors
  @max_number_of_colors
end

#rangeObject (readonly)

Returns the value of attribute range.



3
4
5
# File 'lib/color_picker/palette.rb', line 3

def range
  @range
end

#range_htmlObject (readonly)

Returns the value of attribute range_html.



3
4
5
# File 'lib/color_picker/palette.rb', line 3

def range_html
  @range_html
end

#red_color_rangeObject (readonly)

Returns the value of attribute red_color_range.



4
5
6
# File 'lib/color_picker/palette.rb', line 4

def red_color_range
  @red_color_range
end

Instance Method Details

#complete_paletteObject



16
17
18
19
20
21
# File 'lib/color_picker/palette.rb', line 16

def complete_palette
  @red_color_range =  0 .. 255
  @green_color_range = 0 .. 255
  @blue_color_range = 0 .. 255
  generate_palette
end

#custom_palette(red, green, blue) ⇒ Object



30
31
32
33
34
35
# File 'lib/color_picker/palette.rb', line 30

def custom_palette(red, green, blue)
	@red_color_range = red
	@green_color_range = green
	@blue_color_range = blue
	generate_palette
end

#strong_colorsObject



23
24
25
26
27
28
# File 'lib/color_picker/palette.rb', line 23

def strong_colors
  @red_color_range = 0 .. 7
  @green_color_range = 0 .. 9
  @blue_color_range = 0 .. 159
  generate_palette
end

#to_htmlObject



37
38
39
40
41
42
43
44
45
# File 'lib/color_picker/palette.rb', line 37

def to_html
  @range_html = "<div style='width='600px'; height='auto'; float='left'; clear='both'>"
			
  (0 .. @max_number_of_colors).each do |color_code|
    color_container = "<div style='background= ##{color_code.to_s(16)}'; border= '1px solid #000;'>&nbps;</div><div style='float= left'>#{color_code.to_s(16)}</div>"
    @range_html += color_container
  end
  @range_html += "</div>"
end

#type=(type) ⇒ Object



12
13
14
# File 'lib/color_picker/palette.rb', line 12

def type=(type)
  eval "#{type}" 
end