Class: Spectra::Color

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, components) ⇒ Color

Returns a new instance of Color.



10
11
12
13
# File 'lib/spectra/models/color.rb', line 10

def initialize(name, components)
  self.name = name
  self.components = components
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name) ⇒ Object



19
20
21
# File 'lib/spectra/models/color.rb', line 19

def method_missing(name)
  Components.valid?(name) ? self.components[name] : super
end

Instance Attribute Details

#componentsObject

Returns the value of attribute components.



8
9
10
# File 'lib/spectra/models/color.rb', line 8

def components
  @components
end

#nameObject

Returns the value of attribute name.



8
9
10
# File 'lib/spectra/models/color.rb', line 8

def name
  @name
end

Instance Method Details

#respond_to?(name) ⇒ Boolean

Returns:

  • (Boolean)


15
16
17
# File 'lib/spectra/models/color.rb', line 15

def respond_to?(name)
  super || Components.valid?(name)
end

#to_sObject

Debugging



27
28
29
30
31
32
# File 'lib/spectra/models/color.rb', line 27

def to_s
  string = "color '#{name}'"
  string = [ :red, :green, :blue, :alpha ].inject(string) do |memo, key| 
    memo + ' ' + key.to_s[0] + ' %.2f' % (self.components[key] || 0.0)
  end
end