Class: CSSPool::Color
- Inherits:
-
Object
- Object
- CSSPool::Color
- Defined in:
- lib/css_press/color.rb
Class Method Summary collapse
- .color_val(value, result, hash) ⇒ Object
- .load(name) ⇒ Object
- .min_color(value) ⇒ Object
- .min_hex(value) ⇒ Object
- .min_rgb(value) ⇒ Object
Class Method Details
.color_val(value, result, hash) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/css_press/color.rb', line 20 def color_val value, result, hash val = result.nil? ? value : result if hash && val.length == 6 && val[0] == val[1] && val[2] == val[3] && val[4] == val[5] then val = val.chars.to_a val = result = val[0] + val[2] + val[4] end if !result.nil? then result = hash ? "##{val}" : val end result end |
.load(name) ⇒ Object
7 8 9 10 |
# File 'lib/css_press/color.rb', line 7 def load name data = File.read(File.("../../colors/#{name}.json", __FILE__)) JSON.parse(data) end |
.min_color(value) ⇒ Object
39 40 41 42 43 44 |
# File 'lib/css_press/color.rb', line 39 def min_color value val = value.downcase result = long_to_hex val hash = !result.nil? color_val val, result, hash end |
.min_hex(value) ⇒ Object
32 33 34 35 36 37 |
# File 'lib/css_press/color.rb', line 32 def min_hex value val = value.downcase result = hex_to_short val hash = result.nil? color_val val, result, hash end |
.min_rgb(value) ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/css_press/color.rb', line 46 def min_rgb value rgb = [value.red, value.green, value.blue] rgb.map! do |color| color = color.to_s if color =~ /\%$/ then color = (color[0..-2].to_f / 100 * 256).round else color = color.to_i end if color > 255 then raise ArgumentError.new "Color value should be [0..255] or [0%..100%]" end color end rgb = '%02x%02x%02x' % rgb result = min_hex(rgb) if result.nil? then result = rgb end result end |