Sha256: 1ad1e8863751c07101b6c0f2b2c158e70a34ac3f1f5da5b03e95b9a34ce74c2c

Contents?: true

Size: 993 Bytes

Versions: 29

Compression:

Stored size: 993 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 && 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) + inside

      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

29 entries across 29 versions & 1 rubygems

Version Path
sugarcube-0.19.0 lib/sugarcube/to_s/uicolor.rb
sugarcube-0.18.21 lib/sugarcube/to_s/uicolor.rb
sugarcube-0.18.20 lib/sugarcube/to_s/uicolor.rb
sugarcube-0.18.19 lib/sugarcube/to_s/uicolor.rb
sugarcube-0.18.18 lib/sugarcube/to_s/uicolor.rb
sugarcube-0.18.17 lib/sugarcube/to_s/uicolor.rb
sugarcube-0.18.16 lib/sugarcube/to_s/uicolor.rb
sugarcube-0.18.12 lib/sugarcube/to_s/uicolor.rb
sugarcube-0.18.11 lib/sugarcube/to_s/uicolor.rb
sugarcube-0.18.10 lib/sugarcube/to_s/uicolor.rb
sugarcube-0.18.9 lib/sugarcube/to_s/uicolor.rb
sugarcube-0.18.8 lib/sugarcube/to_s/uicolor.rb
sugarcube-0.18.7 lib/sugarcube/to_s/uicolor.rb
sugarcube-0.18.6 lib/sugarcube/to_s/uicolor.rb
sugarcube-0.18.5 lib/sugarcube/to_s/uicolor.rb
sugarcube-0.18.4 lib/sugarcube/to_s/uicolor.rb
sugarcube-0.18.3 lib/sugarcube/to_s/uicolor.rb
sugarcube-0.18.2 lib/sugarcube/to_s/uicolor.rb
sugarcube-0.18.1 lib/sugarcube/to_s/uicolor.rb
sugarcube-0.18.0 lib/sugarcube/to_s/uicolor.rb