Class: N::ShaderManager

Inherits:
Object
  • Object
show all
Defined in:
lib/n/shaders.rb

Overview

ShaderManager

Manages the shaders for the webapp.

TODO: integrate with sitemap.

Design:

  • the shader selection may be time consuming but is performed once when transforming the script, so its essentially for free (and

anyway the xsl transoformation is orders of magnitude slower)

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeShaderManager

Returns a new instance of ShaderManager.



135
136
137
138
# File 'lib/n/shaders.rb', line 135

def initialize
	@regex = []
	@shaders = []
end

Instance Attribute Details

#default_shaderObject

Returns the value of attribute default_shader.



133
134
135
# File 'lib/n/shaders.rb', line 133

def default_shader
  @default_shader
end

#regexObject

corresponding arrays



132
133
134
# File 'lib/n/shaders.rb', line 132

def regex
  @regex
end

#shadersObject

corresponding arrays



132
133
134
# File 'lib/n/shaders.rb', line 132

def shaders
  @shaders
end

Instance Method Details

#add(regex, shader) ⇒ Object



144
145
146
147
# File 'lib/n/shaders.rb', line 144

def add(regex, shader)
	@regex << regex
	@shaders << shader
end

#delete(regex) ⇒ Object



158
159
160
161
162
163
# File 'lib/n/shaders.rb', line 158

def delete(regex)
	if idx = @regex.index(regex)
		@regex.delete_at(idx)
		@shaders.delete_at(idx)
	end
end

#set_default(shader) ⇒ Object



140
141
142
# File 'lib/n/shaders.rb', line 140

def set_default(shader)
	@default_shader = shader
end

#shader_for_path(path) ⇒ Object



149
150
151
152
153
154
155
156
# File 'lib/n/shaders.rb', line 149

def shader_for_path(path)
	@regex.each_with_index { |rx, idx|
		if path =~ rx
			return @shaders[idx]
		end
	}
	return @default_shader
end