Class: Spectra::Color
- Inherits:
-
Object
- Object
- Spectra::Color
- Defined in:
- lib/spectra/models.rb
Instance Attribute Summary collapse
-
#components ⇒ Object
Returns the value of attribute components.
-
#name ⇒ Object
Returns the value of attribute name.
Instance Method Summary collapse
-
#initialize(name, components) ⇒ Color
constructor
A new instance of Color.
- #method_missing(name) ⇒ Object
- #respond_to?(name) ⇒ Boolean
-
#to_s ⇒ Object
Debugging.
Constructor Details
#initialize(name, components) ⇒ Color
Returns a new instance of Color.
33 34 35 36 |
# File 'lib/spectra/models.rb', line 33 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
42 43 44 |
# File 'lib/spectra/models.rb', line 42 def method_missing(name) Components.valid?(name) ? self.components[name] : super end |
Instance Attribute Details
#components ⇒ Object
Returns the value of attribute components.
31 32 33 |
# File 'lib/spectra/models.rb', line 31 def components @components end |
#name ⇒ Object
Returns the value of attribute name.
31 32 33 |
# File 'lib/spectra/models.rb', line 31 def name @name end |
Instance Method Details
#respond_to?(name) ⇒ Boolean
38 39 40 |
# File 'lib/spectra/models.rb', line 38 def respond_to?(name) super || Components.valid?(name) end |
#to_s ⇒ Object
Debugging
50 51 52 |
# File 'lib/spectra/models.rb', line 50 def to_s "<color: #{name} colors: #{components.values_at(:red, :green, :blue, :alpha).map{|v| v.is_a?(String) ? v : '%.2f' % (v || 0.0) }}>" end |