Class: MindmapDoc

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(s = nil, root: 'root') ⇒ MindmapDoc

Returns a new instance of MindmapDoc.



13
14
15
16
17
18
# File 'lib/mindmapdoc.rb', line 13

def initialize(s=nil, root: 'root')

  @root, @tree, @txtdoc, @svg = root, '', '', ''
  import(s) if s
  
end

Instance Attribute Details

#rootObject

Returns the value of attribute root.



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

def root
  @root
end

Instance Method Details

#import(s) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/mindmapdoc.rb', line 20

def import(s)
  
  if s =~ /^# / then
    @txtdoc = s.gsub(/\r/,'')
    @tree, @html = parse_doc s
  else
    @tree, @txtdoc = parse_tree s
  end

  @svg = build_svg(@tree)    
  
end

#load(s = 'mindmap.md') ⇒ Object



33
34
35
36
# File 'lib/mindmapdoc.rb', line 33

def load(s='mindmap.md')
  buffer = File.read(s)
  import(buffer)
end

#save(s = 'mindmap.md') ⇒ Object



60
61
62
63
# File 'lib/mindmapdoc.rb', line 60

def save(s='mindmap.md')
  File.write s, @txtdoc
  'mindmap written to file'
end

#to_htmlObject



38
39
40
# File 'lib/mindmapdoc.rb', line 38

def to_html()
  @html
end

#to_mdObject Also known as: to_doc



54
55
56
# File 'lib/mindmapdoc.rb', line 54

def to_md()
  @txtdoc
end

#to_svgObject



42
43
44
# File 'lib/mindmapdoc.rb', line 42

def to_svg()
  @svg
end

#to_treeObject Also known as: to_s



46
47
48
49
50
# File 'lib/mindmapdoc.rb', line 46

def to_tree()
  lines = @tree.lines
  lines.shift    
  lines.map! {|x| x[2..-1]}.join
end