lib/ase-palette/palette.rb in ase-palette-0.9.1 vs lib/ase-palette/palette.rb in ase-palette-0.9.2
- old
+ new
@@ -1,9 +1,7 @@
module ASEPalette
- class Palette
- # TODO: Consider removing 'with_name' from method signatures
-
+ class Palette
# Initialize palette
def initialize(path = nil)
@version_major = 1
@version_minor = 0
@colors = []
@@ -69,14 +67,28 @@
end
else
raise Error, "A color named #{color.name} already exists"
end
else
- raise Error, "Argument 'color' is not of type #{ASEPalette::Color}"
+ raise Error, "Argument 'color' must be of type #{ASEPalette::Color}"
end
end
+ # Add multiple colors to palette
+ # 'colors' must be an array of Color objects
+ # Optionally provide 'group_name' to place color in group
+ # Group will be created if it does not exist
+ def add_colors(colors, group_name: nil)
+ if colors.is_a? Array
+ colors.each do |color|
+ add_color(color, group_name: group_name)
+ end
+ else
+ raise Error, "Argument 'colors' must be of type #{Array}"
+ end
+ end
+
# Create empty group in palette
# Returns true if group is created
def create_group(name)
if group_does_not_exist(name)
@groups << ASEPalette::Group.new(name)
@@ -181,16 +193,16 @@
color[:type],
)
end
end
- # Returns an array of all colors in the palette,
+ # Returns a copied array of all colors in palette,
# including those in groups
def all_colors
@colors + @groups.map { |group| group.colors }.flatten
end
- # Determines whether or not a color exists in the palette,
+ # Determines whether color exists in palette,
# including those in groups
def color_does_not_exist(name)
all_colors.select { |color| color.name == name }.length == 0
end
\ No newline at end of file