Class: MindmeisterApi::MindmeisterMapParser

Inherits:
Object
  • Object
show all
Includes:
KLog::Logging
Defined in:
lib/mindmeister_api/mindmeister_map_parser.rb

Overview

Parse a Mindmeister .mind formatted content

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(input_mindmap) ⇒ MindmeisterMapParser

Create a parser for a mindmeister mindmap

Parameters:

  • input_mindmap (Hash)

    Mindmeister formatted object



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_mindmapObject (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

#mindmapObject (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

#parseObject



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

Returns:

  • (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