Class: Passcard::Palette

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/passcard/palette.rb

Constant Summary collapse

GOLDEN_RATIO =
(1 + Math.sqrt(5))/2

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(type = :passcard, options = {}) ⇒ Palette

Returns a new instance of Palette.



9
10
11
12
# File 'lib/passcard/palette.rb', line 9

def initialize(type = :passcard, options = {})
  self.type    = type
  self.options = options
end

Instance Attribute Details

#colorsObject (readonly)

Returns the value of attribute colors.



6
7
8
# File 'lib/passcard/palette.rb', line 6

def colors
  @colors
end

#optionsObject

Returns the value of attribute options.



6
7
8
# File 'lib/passcard/palette.rb', line 6

def options
  @options
end

#typeObject

Returns the value of attribute type.



6
7
8
# File 'lib/passcard/palette.rb', line 6

def type
  @type
end

Instance Method Details

#list_typesObject



37
38
39
40
41
# File 'lib/passcard/palette.rb', line 37

def list_types
  self.methods.map do |method|
    method.to_s.gsub!(/^generate_colors_/, '')
  end.compact.map(&:to_sym)
end

#update_colorsObject



30
31
32
33
34
35
# File 'lib/passcard/palette.rb', line 30

def update_colors
  return unless type && options
  @colors = send("generate_colors_#{type}", options).map do |rgb|
    { color: rgb, text_color: readable_text_color_for(rgb) }
  end
end