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
-
#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
40 41 42 43 |
# File 'lib/spectra/models/spectrum.rb', line 40 def color(name, attributes) self.colors ||= [] self.colors << Color.new(name, Components.componentize(attributes)) end |
#components(*components) ⇒ Object
45 46 47 |
# File 'lib/spectra/models/spectrum.rb', line 45 def components(*components) components.hash_from(:red, :green, :blue, :alpha) end |
#format(type, directory = nil, &renamer) ⇒ Object
35 36 37 38 |
# File 'lib/spectra/models/spectrum.rb', line 35 def format(type, directory = nil, &renamer) self.views ||= [] self.views.concat(Views.from_attributes({ type: type, directory: directory, renamer: renamer })) end |
#formats(*types) ⇒ Object
31 32 33 |
# File 'lib/spectra/models/spectrum.rb', line 31 def formats(*types) types.each { |type| format(type) } end |
#generate(definition) ⇒ Object
12 13 14 15 16 17 18 19 20 21 |
# File 'lib/spectra/models/spectrum.rb', line 12 def generate(definition) # evaluate color definition file, setup defaults self.instance_eval(definition) 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
49 50 51 |
# File 'lib/spectra/models/spectrum.rb', line 49 def hex(*components) components.hash_from(:hex, :alpha) end |
#prefix(prefix) ⇒ Object
DSL
27 28 29 |
# File 'lib/spectra/models/spectrum.rb', line 27 def prefix(prefix) self._prefix = prefix end |
#white(*components) ⇒ Object
53 54 55 |
# File 'lib/spectra/models/spectrum.rb', line 53 def white(*components) components.hash_from(:white, :alpha) end |