class Spectra::View

Attributes

colors[RW]
prefix[RW]
renamer[RW]

Public Class Methods

from_attributes(attributes) click to toggle source
# File lib/spectra/views/view.rb, line 19
def self.from_attributes(attributes)
  [ self.new(attributes) ]
end
new(attributes) click to toggle source
# File lib/spectra/views/view.rb, line 13
def initialize(attributes)
  self.directory = attributes[:directory]
  self.filename  = attributes[:filename]
  self.renamer   = attributes[:renamer]
end
template_name() click to toggle source
Calls superclass method
# File lib/spectra/views/view.rb, line 29
def self.template_name
   super.split('/').last
end

Public Instance Methods

format_color_name(color) click to toggle source
# File lib/spectra/views/view.rb, line 52
def format_color_name(color)
  self.renamer.call(color, self.prefix)
end
format_color_value(value) click to toggle source
# File lib/spectra/views/view.rb, line 56
def format_color_value(value)
  '%.2f' % (value || 0.0)
end
render(attributes) click to toggle source

Rendering

Calls superclass method
# File lib/spectra/views/view.rb, line 37
def render(attributes)
  self.prefix = attributes[:prefix]
  self.colors = self.views_from_colors(attributes[:colors])
  super() # offload to Mustache
end
to_s() click to toggle source

Debugging

# File lib/spectra/views/view.rb, line 64
def to_s
  "<#{self.class.name} => #{self.path}, renamer: #{@renamer}>"
end
views_from_colors(colors) click to toggle source
# File lib/spectra/views/view.rb, line 43
def views_from_colors(colors)
  colors.map do |color| 
    ColorView.new(color, {
      name:  proc { |c| self.format_color_name(c) },
      value: proc { |v| self.format_color_value(v) }
    }) 
  end
end