Commit 89c299773cde818dab730229a63b6930da211418
1 parent
a010f291
Exists in
master
validates custom palettes
Showing
1 changed file
with
11 additions
and
0 deletions
Show diff stats
lib/letter_avatar/colors.rb
@@ -276,8 +276,19 @@ module LetterAvatar | @@ -276,8 +276,19 @@ module LetterAvatar | ||
276 | 276 | ||
277 | def self.with_custom(username) | 277 | def self.with_custom(username) |
278 | custom_palette = LetterAvatar.custom_palette | 278 | custom_palette = LetterAvatar.custom_palette |
279 | + raise "Missing Custom Palette, please set config.custom_palette if using :custom" if custom_palette.nil? | ||
280 | + raise "Invalid Custom Palette, please update config.custom_palette" unless valid_custom_palette | ||
279 | custom_palette[Digest::MD5.hexdigest(username)[0...15].to_i(16) % custom_palette.length] | 281 | custom_palette[Digest::MD5.hexdigest(username)[0...15].to_i(16) % custom_palette.length] |
280 | end | 282 | end |
283 | + | ||
284 | + def self.valid_custom_palette | ||
285 | + palette = LetterAvatar.custom_palette | ||
286 | + return false unless palette.is_a?(Array) | ||
287 | + return palette.all? do |color| | ||
288 | + false unless color.is_a?(Array) | ||
289 | + color.all? {|i| i.is_a?(Integer) } | ||
290 | + end | ||
291 | + end | ||
281 | 292 | ||
282 | # Colors form Google Inbox | 293 | # Colors form Google Inbox |
283 | # https://inbox.google.com | 294 | # https://inbox.google.com |