Class: Spectra::Spectrum
- Inherits:
-
Object
- Object
- Spectra::Spectrum
- Defined in:
- lib/spectra/models/spectrum.rb
Instance Attribute Summary collapse
-
#_prefix ⇒ Object
Returns the value of attribute _prefix.
-
#colors ⇒ Object
Returns the value of attribute colors.
-
#views ⇒ Object
Returns the value of attribute views.
Instance Method Summary collapse
- #color(name, attributes) ⇒ Object
- #components(*components) ⇒ Object
- #format(type, directory = nil, &renamer) ⇒ Object
- #formats(*types) ⇒ Object
- #generate(definition) ⇒ Object
- #hex(*components) ⇒ Object
-
#log_report ⇒ Object
Debug.
-
#prefix(prefix) ⇒ Object
DSL.
- #white(*components) ⇒ Object
Instance Attribute Details
#_prefix ⇒ Object
Returns the value of attribute _prefix.
9 10 11 |
# File 'lib/spectra/models/spectrum.rb', line 9 def _prefix @_prefix end |
#colors ⇒ Object
Returns the value of attribute colors.
10 11 12 |
# File 'lib/spectra/models/spectrum.rb', line 10 def colors @colors end |
#views ⇒ Object
Returns the value of attribute views.
10 11 12 |
# File 'lib/spectra/models/spectrum.rb', line 10 def views @views end |
Instance Method Details
#color(name, attributes) ⇒ Object
43 44 45 46 |
# File 'lib/spectra/models/spectrum.rb', line 43 def color(name, attributes) self.colors ||= [] self.colors << Color.new(name, Components.componentize(attributes)) end |
#components(*components) ⇒ Object
48 49 50 |
# File 'lib/spectra/models/spectrum.rb', line 48 def components(*components) components.hash_from(:red, :green, :blue, :alpha) end |
#format(type, directory = nil, &renamer) ⇒ Object
38 39 40 41 |
# File 'lib/spectra/models/spectrum.rb', line 38 def format(type, directory = nil, &renamer) self.views ||= [] self.views.concat(Views.from_attributes({ type: type, directory: directory, renamer: renamer })) end |
#formats(*types) ⇒ Object
34 35 36 |
# File 'lib/spectra/models/spectrum.rb', line 34 def formats(*types) types.each { |type| format(type) } end |
#generate(definition) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/spectra/models/spectrum.rb', line 12 def generate(definition) # evaluate color definition file, setup defaults self.instance_eval(definition) self.log_report() # pull in default formats if we don't have any self.formats(:palette, :objc) unless self.views # render views according to the specification self.views.each do |view| view.serialize({ colors: self.colors, prefix: self._prefix }) end end |
#hex(*components) ⇒ Object
52 53 54 |
# File 'lib/spectra/models/spectrum.rb', line 52 def hex(*components) components.hash_from(:hex, :alpha) end |
#log_report ⇒ Object
Debug
64 65 66 67 68 69 70 |
# File 'lib/spectra/models/spectrum.rb', line 64 def log_report color_info = self.colors.inject("") do |memo, color| memo += "[∫] Evaluated #{color}\n" end Spectra.logger.debug(color_info) end |
#prefix(prefix) ⇒ Object
DSL
30 31 32 |
# File 'lib/spectra/models/spectrum.rb', line 30 def prefix(prefix) self._prefix = prefix end |
#white(*components) ⇒ Object
56 57 58 |
# File 'lib/spectra/models/spectrum.rb', line 56 def white(*components) components.hash_from(:white, :alpha) end |