Class: Spectra::Spectrum

Inherits:
Object
  • Object
show all
Defined in:
lib/spectra/models/spectrum.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#_prefixObject

Returns the value of attribute _prefix.



9
10
11
# File 'lib/spectra/models/spectrum.rb', line 9

def _prefix
  @_prefix
end

#colorsObject

Returns the value of attribute colors.



10
11
12
# File 'lib/spectra/models/spectrum.rb', line 10

def colors
  @colors
end

#viewsObject

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_reportObject

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