Sha256: 19775b4c7b18adb23ef07196743712f6ce932fe5c2df6abe4ab0021e106c0bac

Contents?: true

Size: 970 Bytes

Versions: 3

Compression:

Stored size: 970 Bytes

Contents

class UIColor
  def to_s
    system_color = nil
    Symbol.uicolors.each_pair do |color, method|
      if UIColor.send(method) == self
        if self.alpha < 1
          system_color = "UIColor.#{method}(#{alpha})"
        else
          system_color = "UIColor.#{method}"
        end
        break
      end
    end
    return system_color if system_color

    if self.red && self.green && self.blue
      red = (self.red * 255).round << 16
      green = (self.green * 255).round << 8
      blue = (self.blue * 255).round
      my_color = red + green + blue

      inside = my_color.to_s(16)
      inside = '0x' + '0' * (6 - inside.length)

      Symbol.css_colors.each_pair do |color, hex|
        if hex == my_color
          inside = color.inspect
          break
        end
      end

      if self.alpha < 1
        return "UIColor.color(#{inside}, #{alpha})"
      else
        return "UIColor.color(#{inside})"
      end
    else
      super
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
sugarcube-0.13.5 lib/sugarcube/to_s/uicolor.rb
sugarcube-0.13.4 lib/sugarcube/to_s/uicolor.rb
sugarcube-0.13.3 lib/sugarcube/to_s/uicolor.rb