class

Opal::PaletteModel

Inherits Reference < Object

Core data model for a color palette. Encapsulates either a Named palette (String -> Color) or an Indexed palette (Array(Color)), with min/max size constraints, add/rename/remove/reorder permissions, and format conversion.

Constructors

from_content(content : String, format : PaletteFormat) : PaletteModel
Source
from_file(path : String) : PaletteModel

Parsing / importing constructors

Source
new(mode : PaletteMode = PaletteMode::Indexed, indexed_colors : Array(Color) | Nil = nil, named_entries : Array(NamedColorEntry | Tuple(String, Color)) | Hash(String, Color) | Nil = nil, min_colors : Int32 | Nil = nil, max_colors : Int32 | Nil = nil, allow_add : Bool = true, allow_rename : Bool = true, allow_remove : Bool = true, allow_reorder : Bool = true, palette_name : String = "Opal Palette")
Source

Class methods

detect_format(content : String) : PaletteFormat
Source

Instance methods

add(color : Color, name : String | Nil = nil) : Bool

Modification operations

Source
allow_add=(allow_add : Bool)

Action permissions

Source
allow_add?

Action permissions

Source
allow_remove=(allow_remove : Bool)
Source
allow_remove?
Source
allow_rename=(allow_rename : Bool)
Source
allow_rename?
Source
allow_reorder=(allow_reorder : Bool)
Source
allow_reorder?
Source
can_add?

Permission checks

Source
can_remove?
Source
can_rename?
Source
can_reorder?
Source
color_at(index : Int32) : Color | Nil

Returns entry at index

Source
colors

Returns array of colors in current display order

Source
empty?
Source
export(format : PaletteFormat | Symbol | String, name : String = @palette_name) : String
Source
indexed_colors
Source
indexed_colors=(indexed_colors : Array(Color))
Source
max_colors
Source
max_colors=(max_colors : Int32 | Nil)
Source
min_colors

Size restrictions (nil = unbounded)

Source
min_colors=(min_colors : Int32 | Nil)

Size restrictions (nil = unbounded)

Source
mode
Source
mode=(mode : PaletteMode)
Source
move(from_idx : Int32, to_idx : Int32) : Bool

Move item from one position to another

Source
name_at(index : Int32) : String | Nil
Source
named_entries
Source
named_entries=(named_entries : Array(NamedColorEntry))
Source
palette_name
Source
palette_name=(palette_name : String)
Source
remove_at(index : Int32) : Bool
Source
rename(index : Int32, new_name : String) : Bool
Source
size

Total count of colors/entries

Source
swap(index_a : Int32, index_b : Int32) : Bool

Swap two indices (used for [ and ] reordering)

Source
to_css(prefix : String = "") : String
Source
to_gpl(name : String = @palette_name) : String

Export format methods

Source
to_hex(with_hash : Bool = true) : String
Source
to_json
Source
to_pal
Source
update_color(index : Int32, color : Color) : Bool
Source