Class: RubyXL::ColorConvenienceClasses::RgbColor
- Inherits:
-
Object
- Object
- RubyXL::ColorConvenienceClasses::RgbColor
- Defined in:
- lib/rubyXL/convenience_methods.rb
Overview
Instance Attribute Summary collapse
-
#a ⇒ Object
Returns the value of attribute a.
-
#b ⇒ Object
Returns the value of attribute b.
-
#g ⇒ Object
Returns the value of attribute g.
-
#r ⇒ Object
Returns the value of attribute r.
Class Method Summary collapse
Instance Method Summary collapse
Instance Attribute Details
#a ⇒ Object
Returns the value of attribute a.
1167 1168 1169 |
# File 'lib/rubyXL/convenience_methods.rb', line 1167 def a @a end |
#b ⇒ Object
Returns the value of attribute b.
1167 1168 1169 |
# File 'lib/rubyXL/convenience_methods.rb', line 1167 def b @b end |
#g ⇒ Object
Returns the value of attribute g.
1167 1168 1169 |
# File 'lib/rubyXL/convenience_methods.rb', line 1167 def g @g end |
#r ⇒ Object
Returns the value of attribute r.
1167 1168 1169 |
# File 'lib/rubyXL/convenience_methods.rb', line 1167 def r @r end |
Class Method Details
.parse(str) ⇒ Object
1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 |
# File 'lib/rubyXL/convenience_methods.rb', line 1207 def self.parse(str) r, g, b, a = str.unpack("A2A2A2A2") rgb_color = RgbColor.new rgb_color.r = r && r.to_i(16) rgb_color.g = g && g.to_i(16) rgb_color.b = b && b.to_i(16) rgb_color.a = a && a.to_i(16) rgb_color end |
Instance Method Details
#to_hls ⇒ Object
1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 |
# File 'lib/rubyXL/convenience_methods.rb', line 1169 def to_hls hls_color = HlsColor.new # Note that we are overriding accessors with local vars here: r = self.r / 255.0 g = self.g / 255.0 b = self.b / 255.0 hls_color.a = (self.a || 0) / 255.0 min = [r, g, b].min max = [r, g, b].max delta = max - min if (max == min) then hls_color.h = hls_color.s = 0 hls_color.l = max return hls_color end hls_color.l = (min + max) / 2 if (hls_color.l < 0.5) then hls_color.s = delta / (max + min); else hls_color.s = delta / (2.0 - max - min); end hls_color.h = (g - b) / delta if (r == max) hls_color.h = 2.0 + (b - r) / delta if (g == max) hls_color.h = 4.0 + (r - g) / delta if (b == max) hls_color.h *= 60; hls_color.h += 360 if hls_color.h < 0 hls_color end |
#to_s ⇒ Object
1219 1220 1221 1222 1223 |
# File 'lib/rubyXL/convenience_methods.rb', line 1219 def to_s str = r.to_s(16) + g.to_s(16) + b.to_s(16) str += a.to_s(16) if a && a != 0 str end |