Sha256: c1facd4af001f8cf0735c3e7cebc92b1a519ee10bcaa1f3bf9ead2cce7ff81ca

Contents?: true

Size: 1.17 KB

Versions: 1

Compression:

Stored size: 1.17 KB

Contents

module LetterAvatar
  module Colors

    # Colors form Google Inbox
    # https://inbox.google.com
    COLORS = [
      [226, 95, 81], # A
      [242, 96, 145], # B
      [187, 101, 202], # C
      [149, 114, 207], # D
      [120, 132, 205], # E
      [91, 149, 249], # F
      [72, 194, 249], # G
      [69, 208, 226], # H
      [72, 182, 172], # I
      [82, 188, 137], # J
      [155, 206, 95], # K
      [212, 227, 74], # L
      [254, 218, 16], # M
      [247, 192, 0], # N
      [255, 168, 0], # O
      [255, 138, 96], # P
      [194, 194, 194], # Q
      [143, 164, 175], # R
      [162, 136, 126], # S
      [163, 163, 163], # T
      [175, 181, 226], # U
      [179, 155, 221], # V
      [194, 194, 194], # W
      [124, 222, 235], # X
      [188, 170, 164], # Y
      [173, 214, 125] # Z
    ]

    def self.for(username)
      char = username[0]
      char.upcase!
      if /[A-Z]/.match(char)
        # 65 is 'A' ord
        idx = char.ord - 65
        return all[idx]
      end

      if /[\d]/.match(char)
        return all[char.to_i]
      end

      all[Digest::MD5.hexdigest(username)[0...15].to_i(16) % all.length]
    end

    def self.all
      COLORS
    end

  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
letter_avatar-0.1.0 lib/letter_avatar/colors.rb