Class: MindmapDoc
- Inherits:
-
Object
- Object
- MindmapDoc
- Defined in:
- lib/mindmapdoc.rb
Instance Attribute Summary collapse
-
#root ⇒ Object
Returns the value of attribute root.
Instance Method Summary collapse
- #import(s) ⇒ Object
-
#initialize(s = nil, root: 'root') ⇒ MindmapDoc
constructor
A new instance of MindmapDoc.
- #load(s = 'mindmap.md') ⇒ Object
- #save(s = 'mindmap.md') ⇒ Object
- #to_html ⇒ Object
- #to_md ⇒ Object (also: #to_doc)
- #to_svg ⇒ Object
- #to_tree ⇒ Object (also: #to_s)
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
#root ⇒ Object
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_html ⇒ Object
38 39 40 |
# File 'lib/mindmapdoc.rb', line 38 def to_html() @html end |
#to_md ⇒ Object Also known as: to_doc
54 55 56 |
# File 'lib/mindmapdoc.rb', line 54 def to_md() @txtdoc end |
#to_svg ⇒ Object
42 43 44 |
# File 'lib/mindmapdoc.rb', line 42 def to_svg() @svg end |
#to_tree ⇒ Object 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 |