Class: Spectra::ColorView
- Inherits:
-
Object
- Object
- Spectra::ColorView
- Defined in:
- lib/spectra/views/view.rb
Instance Attribute Summary collapse
-
#color ⇒ Object
Returns the value of attribute color.
-
#formatters ⇒ Object
Returns the value of attribute formatters.
Instance Method Summary collapse
- #format(type, value) ⇒ Object
- #grayscale? ⇒ Boolean
- #hex ⇒ Object
-
#initialize(color, formatters) ⇒ ColorView
constructor
A new instance of ColorView.
- #method_missing(name, *args) ⇒ Object
-
#name ⇒ Object
Accessors.
- #respond_to?(name) ⇒ Boolean
-
#to_s ⇒ Object
Debugging.
Constructor Details
#initialize(color, formatters) ⇒ ColorView
Returns a new instance of ColorView.
74 75 76 77 |
# File 'lib/spectra/views/view.rb', line 74 def initialize(color, formatters) self.color = color self.formatters = formatters end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args) ⇒ Object
83 84 85 86 87 88 89 |
# File 'lib/spectra/views/view.rb', line 83 def method_missing(name, *args) if Components.valid?(name) self.format(:value, self.color.send(name, *args)) else super end end |
Instance Attribute Details
#color ⇒ Object
Returns the value of attribute color.
72 73 74 |
# File 'lib/spectra/views/view.rb', line 72 def color @color end |
#formatters ⇒ Object
Returns the value of attribute formatters.
72 73 74 |
# File 'lib/spectra/views/view.rb', line 72 def formatters @formatters end |
Instance Method Details
#format(type, value) ⇒ Object
107 108 109 |
# File 'lib/spectra/views/view.rb', line 107 def format(type, value) self.formatters[type].call(value) end |
#grayscale? ⇒ Boolean
99 100 101 |
# File 'lib/spectra/views/view.rb', line 99 def grayscale? self.color.components[:white] end |
#hex ⇒ Object
103 104 105 |
# File 'lib/spectra/views/view.rb', line 103 def hex self.format(:value, Components.hexify(self.color.components)) end |
#name ⇒ Object
Accessors
95 96 97 |
# File 'lib/spectra/views/view.rb', line 95 def name self.format(:name, self.color) end |
#respond_to?(name) ⇒ Boolean
79 80 81 |
# File 'lib/spectra/views/view.rb', line 79 def respond_to?(name) super || self.color.respond_to?(name) end |
#to_s ⇒ Object
Debugging
115 116 117 |
# File 'lib/spectra/views/view.rb', line 115 def to_s "<view => #{self.color}>" end |