Module: Mindmap::Node

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

Overview

a module that must be included 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 attributes with the same name



16
17
18
19
20
21
22
# File 'lib/mindmap/node.rb', line 16

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

#initialize(params = {}) ⇒ Object



11
12
13
# File 'lib/mindmap/node.rb', line 11

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

#render(format = :html) ⇒ Object

renders the node ERB view file and returns the result



25
26
27
# File 'lib/mindmap/node.rb', line 25

def render(format = :html)
  Renderer.render("#{view}.#{format}", binding)
end

#urlObject

returns the node url that could be used for a link



37
38
39
# File 'lib/mindmap/node.rb', line 37

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

#viewObject

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



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

def view
  self.class.name.underscore
end