Module: Mindmap::Node

Includes:
ERB::Util
Defined in:
lib/mindmap/node.rb

Overview

a module that must be encluded to any graph node it has methods needed by the framework to render the node

Instance Method Summary collapse

Instance Method Details

#assign_params(params) ⇒ Object

assign a hash values to params with the same name



14
15
16
17
18
# File 'lib/mindmap/node.rb', line 14

def assign_params(params)
  params.each do |key, value|
    public_send("#{key}=", value) if self.class.public_method_defined?("#{key}=")
  end
end

#initialize(params = {}) ⇒ Object



9
10
11
# File 'lib/mindmap/node.rb', line 9

def initialize(params = {})
  assign_params(params)
end

#renderObject

renders the node ERB view file and returns the result



21
22
23
# File 'lib/mindmap/node.rb', line 21

def render
  Renderer.render(view, binding)
end

#urlObject



32
33
34
# File 'lib/mindmap/node.rb', line 32

def url
  '/' + self.class.name.underscore.gsub('_node', '')
end

#viewObject

The path to the view file relative to the “views” directory by default the file is the class name underscored e.g if node class is ‘Graph::NodeName` it returns `graph/node_name`



28
29
30
# File 'lib/mindmap/node.rb', line 28

def view
  self.class.name.underscore
end