Class: Featuremap::Mindmap
- Inherits:
-
Object
- Object
- Featuremap::Mindmap
- Defined in:
- lib/mindmap.rb
Instance Method Summary collapse
-
#add_node(p_node_text, p_node_type, p_parent_node = nil) ⇒ Object
add a new node.
-
#create_node(p_node_text, p_node_type) ⇒ Object
create a new node.
-
#initialize(p_logger) ⇒ Mindmap
constructor
A new instance of Mindmap.
-
#nodes_to_s(p_nodes, p_nodes_text = "") ⇒ Object
turn hash of nodes into mindmap xml string.
-
#to_s ⇒ Object
convert mindmap object to string.
Constructor Details
#initialize(p_logger) ⇒ Mindmap
Returns a new instance of Mindmap.
4 5 6 7 8 9 |
# File 'lib/mindmap.rb', line 4 def initialize(p_logger) @log = p_logger @nodes = [] root_node = create_node("featuremap","root") @nodes.insert(0, root_node) end |
Instance Method Details
#add_node(p_node_text, p_node_type, p_parent_node = nil) ⇒ Object
add a new node
26 27 28 29 30 31 32 33 34 |
# File 'lib/mindmap.rb', line 26 def add_node(p_node_text, p_node_type, p_parent_node = nil) new_node = create_node(p_node_text, p_node_type) # add new node on top level per default if p_parent_node.nil? p_parent_node = @nodes[0] end p_parent_node["nodes"].insert(0, new_node) return new_node end |
#create_node(p_node_text, p_node_type) ⇒ Object
create a new node
21 22 23 |
# File 'lib/mindmap.rb', line 21 def create_node(p_node_text, p_node_type) node = {"created" => Time.now.to_i, "id" => SecureRandom.uuid.gsub(/-/,''), "modified" => Time.now.to_i, "text" => p_node_text, "type" => p_node_type, "nodes" => []} end |
#nodes_to_s(p_nodes, p_nodes_text = "") ⇒ Object
turn hash of nodes into mindmap xml string
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/mindmap.rb', line 37 def nodes_to_s(p_nodes, p_nodes_text="") nodes_text = p_nodes_text #@log.debug nodes_text p_nodes.each do |node| nodes_text << "<node CREATED=\"#{node["created"]}\" ID=\"#{node["type"]}_#{node["id"]}\" MODIFIED=\"#{node["modified"]}\" TEXT=\"#{node["text"]}\">\n" # add icons and fonts to nodes case node["type"] when "feature" nodes_text << "<font BOLD=\"true\" NAME=\"SansSerif\" SIZE=\"12\"/>" when "subdir" nodes_text << "<icon BUILTIN=\"folder\"/>\n" when "scenario_outline" nodes_text << "<icon BUILTIN=\"list\"/>\n" end # call function recursively for sublevel nodes if not node["nodes"].empty? nodes_to_s(node["nodes"], nodes_text) end nodes_text << "</node>\n" end return nodes_text end |
#to_s ⇒ Object
convert mindmap object to string
12 13 14 15 16 17 18 |
# File 'lib/mindmap.rb', line 12 def to_s map = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" map << "<map version=\"1.0.1\">\n" map << "<!-- To view this file, download free mind mapping software FreeMind from http://freemind.sourceforge.net -->\n" map << nodes_to_s(@nodes) map << "</map>\n" end |