Class: Spectra::View
- Inherits:
-
Mustache
- Object
- Mustache
- Spectra::View
- Includes:
- Serializable
- Defined in:
- lib/spectra/views/view.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#colors ⇒ Object
Returns the value of attribute colors.
-
#prefix ⇒ Object
Returns the value of attribute prefix.
-
#renamer ⇒ Object
Returns the value of attribute renamer.
Attributes included from Serializable
Class Method Summary collapse
Instance Method Summary collapse
- #format_color_name(color) ⇒ Object
- #format_color_value(value) ⇒ Object
-
#initialize(attributes) ⇒ View
constructor
A new instance of View.
-
#render(attributes) ⇒ Object
Rendering.
-
#to_s ⇒ Object
Debugging.
- #views_from_colors(colors) ⇒ Object
Methods included from Serializable
#destination, #serialize, #write_file
Constructor Details
#initialize(attributes) ⇒ View
Returns a new instance of View.
13 14 15 16 17 |
# File 'lib/spectra/views/view.rb', line 13 def initialize(attributes) self.directory = attributes[:directory] self.filename = attributes[:filename] self.renamer = attributes[:renamer] end |
Instance Attribute Details
#colors ⇒ Object
Returns the value of attribute colors.
11 12 13 |
# File 'lib/spectra/views/view.rb', line 11 def colors @colors end |
#prefix ⇒ Object
Returns the value of attribute prefix.
11 12 13 |
# File 'lib/spectra/views/view.rb', line 11 def prefix @prefix end |
#renamer ⇒ Object
Returns the value of attribute renamer.
11 12 13 |
# File 'lib/spectra/views/view.rb', line 11 def renamer @renamer end |
Class Method Details
.from_attributes(attributes) ⇒ Object
19 20 21 |
# File 'lib/spectra/views/view.rb', line 19 def self.from_attributes(attributes) [ self.new(attributes) ] end |
.template_name ⇒ Object
29 30 31 |
# File 'lib/spectra/views/view.rb', line 29 def self.template_name super.split('/').last end |
Instance Method Details
#format_color_name(color) ⇒ Object
52 53 54 |
# File 'lib/spectra/views/view.rb', line 52 def format_color_name(color) self.renamer.call(color, self.prefix) end |
#format_color_value(value) ⇒ Object
56 57 58 |
# File 'lib/spectra/views/view.rb', line 56 def format_color_value(value) '%.2f' % (value || 0.0) end |
#render(attributes) ⇒ Object
Rendering
37 38 39 40 41 |
# 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 ⇒ Object
Debugging
64 65 66 |
# File 'lib/spectra/views/view.rb', line 64 def to_s "<#{self.class.name} => #{self.path}, renamer: #{@renamer}>" end |