Class: Spectra::Color
- Inherits:
-
Object
- Object
- Spectra::Color
- Defined in:
- lib/spectra/models/color.rb
Instance Attribute Summary collapse
-
#components ⇒ Object
Returns the value of attribute components.
-
#name ⇒ Object
Returns the value of attribute name.
-
#suffix ⇒ Object
Returns the value of attribute suffix.
Instance Method Summary collapse
-
#initialize(name, components) ⇒ Color
constructor
A new instance of Color.
- #method_missing(name) ⇒ Object
- #parse_name(name) ⇒ Object
-
#respond_to?(name) ⇒ Boolean
Forwarding.
-
#to_s ⇒ Object
Debugging.
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, self.suffix = self.parse_name(name) self.components = components end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name) ⇒ Object
28 29 30 |
# File 'lib/spectra/models/color.rb', line 28 def method_missing(name) Components.valid?(name) ? self.components[name] : super end |
Instance Attribute Details
#components ⇒ Object
Returns the value of attribute components.
8 9 10 |
# File 'lib/spectra/models/color.rb', line 8 def components @components end |
#name ⇒ Object
Returns the value of attribute name.
8 9 10 |
# File 'lib/spectra/models/color.rb', line 8 def name @name end |
#suffix ⇒ Object
Returns the value of attribute suffix.
8 9 10 |
# File 'lib/spectra/models/color.rb', line 8 def suffix @suffix end |
Instance Method Details
#parse_name(name) ⇒ Object
15 16 17 18 |
# File 'lib/spectra/models/color.rb', line 15 def parse_name(name) name_parts = name.to_s.split(/(\d+)/) return name_parts.first, name_parts[1] || '' end |
#respond_to?(name) ⇒ Boolean
Forwarding
24 25 26 |
# File 'lib/spectra/models/color.rb', line 24 def respond_to?(name) super || Components.valid?(name) end |
#to_s ⇒ Object
Debugging
36 37 38 39 40 41 |
# File 'lib/spectra/models/color.rb', line 36 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 |