Class: MindmeisterApi::MindmeisterMapParser
- Inherits:
-
Object
- Object
- MindmeisterApi::MindmeisterMapParser
- Includes:
- KLog::Logging
- Defined in:
- lib/mindmeister_api/mindmeister_map_parser.rb
Overview
Parse a Mindmeister .mind formatted content
Instance Attribute Summary collapse
-
#input_mindmap ⇒ Object
readonly
Returns the value of attribute input_mindmap.
-
#mindmap ⇒ Object
readonly
Returns the value of attribute mindmap.
Class Method Summary collapse
-
.json_file_parser(json_file) ⇒ Object
Factory for creating a parser for an existing mindmap .json file.
Instance Method Summary collapse
-
#initialize(input_mindmap) ⇒ MindmeisterMapParser
constructor
Create a parser for a mindmeister mindmap.
- #parse ⇒ Object
- #valid? ⇒ Boolean
Constructor Details
#initialize(input_mindmap) ⇒ MindmeisterMapParser
Create a parser for a mindmeister mindmap
14 15 16 |
# File 'lib/mindmeister_api/mindmeister_map_parser.rb', line 14 def initialize(input_mindmap) @input_mindmap = input_mindmap end |
Instance Attribute Details
#input_mindmap ⇒ Object (readonly)
Returns the value of attribute input_mindmap.
8 9 10 |
# File 'lib/mindmeister_api/mindmeister_map_parser.rb', line 8 def input_mindmap @input_mindmap end |
#mindmap ⇒ Object (readonly)
Returns the value of attribute mindmap.
9 10 11 |
# File 'lib/mindmeister_api/mindmeister_map_parser.rb', line 9 def mindmap @mindmap end |
Class Method Details
.json_file_parser(json_file) ⇒ Object
Factory for creating a parser for an existing mindmap .json file
20 21 22 23 24 25 26 |
# File 'lib/mindmeister_api/mindmeister_map_parser.rb', line 20 def json_file_parser(json_file) raise MindmeisterApi::Error, "File not found: #{json_file}" unless File.exist?(json_file) content = File.read(json_file) json = JSON.parse(content) new(json) end |
Instance Method Details
#parse ⇒ Object
36 37 38 39 40 |
# File 'lib/mindmeister_api/mindmeister_map_parser.rb', line 36 def parse @mindmap = parse_node(input_mindmap['root'], 1) if valid? self end |
#valid? ⇒ Boolean
29 30 31 32 33 34 |
# File 'lib/mindmeister_api/mindmeister_map_parser.rb', line 29 def valid? return false if input_mindmap.nil? || input_mindmap == {} return false unless input_mindmap['root'] && input_mindmap['root']['id'] true end |