Class: Spectra::ColorView

Inherits:
Object
  • Object
show all
Defined in:
lib/spectra/views/view.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#colorObject

Returns the value of attribute color.



72
73
74
# File 'lib/spectra/views/view.rb', line 72

def color
  @color
end

#formattersObject

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

Returns:

  • (Boolean)


99
100
101
# File 'lib/spectra/views/view.rb', line 99

def grayscale?
  self.color.components[:white] 
end

#hexObject



103
104
105
# File 'lib/spectra/views/view.rb', line 103

def hex
  self.format(:value, Components.hexify(self.color.components))
end

#nameObject

Accessors



95
96
97
# File 'lib/spectra/views/view.rb', line 95

def name
  self.format(:name, self.color)
end

#respond_to?(name) ⇒ Boolean

Returns:

  • (Boolean)


79
80
81
# File 'lib/spectra/views/view.rb', line 79

def respond_to?(name)
  super || self.color.respond_to?(name)
end

#to_sObject

Debugging



115
116
117
# File 'lib/spectra/views/view.rb', line 115

def to_s
  "<view => #{self.color}>"
end