Module: ColorNamerRuby
- Defined in:
- lib/color_namer_ruby.rb,
lib/color_namer_ruby/version.rb,
lib/color_namer_ruby/distance.rb
Defined Under Namespace
Constant Summary collapse
- VERSION =
'0.1.2'
Class Method Summary collapse
-
.get_all_colours(pick: [], omit: []) ⇒ Object
if the same names appear in multiple lists, they could still appear even if certain lists they are in are omitted.
- .get_all_names(pick: [], omit: []) ⇒ Object
- .get_colour(colour_value, pick: [], omit: [], **alt_colour_value) ⇒ Object
- .get_colours(colour_value, pick: [], omit: [], limit: -1,, **alt_colour_value) ⇒ Object
- .get_name(colour_value, pick: [], omit: [], **alt_colour_value) ⇒ Object
- .get_names(colour_value, pick: [], omit: [], limit: -1,, **alt_colour_value) ⇒ Object
- .list_collections ⇒ Object
Class Method Details
.get_all_colours(pick: [], omit: []) ⇒ Object
if the same names appear in multiple lists, they could still appear even if certain lists they are in are omitted
51 52 53 |
# File 'lib/color_namer_ruby.rb', line 51 def self.get_all_colours(pick: [], omit: []) ColorSwatchCollection.get_colours(pick: pick, omit: omit) end |
.get_all_names(pick: [], omit: []) ⇒ Object
23 24 25 |
# File 'lib/color_namer_ruby.rb', line 23 def self.get_all_names(pick: [], omit: []) self.get_all_colours(pick: pick, omit: omit).map { |h| h[:name] } || [] end |
.get_colour(colour_value, pick: [], omit: [], **alt_colour_value) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/color_namer_ruby.rb', line 27 def self.get_colour(colour_value, pick: [], omit: [], **alt_colour_value) # alt_colour_value are used to collect colour paramaters when they are passed in the key format hex = ColorConversion::Color.new(colour_value.presence || alt_colour_value).hex # if we get an exact match, return it colour = self.get_colour_from_collections(hex, pick, omit) if colour.present? colour[:distance] = 0.0 return [colour] end # if we don't get an exact match, try to find the closest match ColorNamerRuby::Distance.get_names_from_hex(hex, pick, omit, 1) end |
.get_colours(colour_value, pick: [], omit: [], limit: -1,, **alt_colour_value) ⇒ Object
43 44 45 46 47 48 |
# File 'lib/color_namer_ruby.rb', line 43 def self.get_colours(colour_value, pick: [], omit: [], limit: -1, **alt_colour_value) hex = ColorConversion::Color.new(colour_value.presence || alt_colour_value).hex # get the closest matches up to the count limit ColorNamerRuby::Distance.get_names_from_hex(hex, pick, omit, limit) end |
.get_name(colour_value, pick: [], omit: [], **alt_colour_value) ⇒ Object
15 16 17 |
# File 'lib/color_namer_ruby.rb', line 15 def self.get_name(colour_value, pick: [], omit: [], **alt_colour_value) self.get_colour(colour_value, pick: pick, omit: omit, **alt_colour_value).map { |h| h[:name] } || [] end |
.get_names(colour_value, pick: [], omit: [], limit: -1,, **alt_colour_value) ⇒ Object
19 20 21 |
# File 'lib/color_namer_ruby.rb', line 19 def self.get_names(colour_value, pick: [], omit: [], limit: -1, **alt_colour_value) self.get_colours(colour_value, pick: pick, omit: omit, limit: limit, **alt_colour_value).map { |h| h[:name] } || [] end |
.list_collections ⇒ Object
11 12 13 |
# File 'lib/color_namer_ruby.rb', line 11 def self.list_collections ColorSwatchCollection.list_collections end |