Class: Color::RGB

Inherits:
Object
  • Object
show all
Defined in:
lib/wasko/color.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.from_applescript(applescript_string) ⇒ Object

Creates a ‘color` from an `Applescript` string, `Applescript` uses `short int` to make the RGB, `65535` is the maximum.

Example:

Color::RGB.from_applescript "65535,65535,65535"
  => <RGB [#ffffff]>


15
16
17
18
19
20
21
22
# File 'lib/wasko/color.rb', line 15

def from_applescript(applescript_string)
  applescript_string.gsub!(/\{|\}/, "")
  rgb = applescript_string.strip.split(",")
  colors = rgb.map do |value|
    value.to_i / 257
  end
  Color::RGB.new(*colors)
end

Instance Method Details

#to_applescriptObject

Converts an instance of ‘Color` to an `Applescript` string color format.



27
28
29
30
# File 'lib/wasko/color.rb', line 27

def to_applescript
  rgb = [self.red.to_i * 257, self.green.to_i * 257, self.blue.to_i * 257].join(", ")
  "{#{rgb}}"
end