Class: Marko::Model::Topic

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Includes:
TreeNode
Defined in:
lib/marko/model/topic.rb

Overview

Topic

Instance Attribute Summary collapse

Attributes included from TreeNode

#parent

Instance Method Summary collapse

Methods included from TreeNode

#nesting_level, #root, #root?

Constructor Details

#initialize(title, content, **metadata) ⇒ Topic

Returns a new instance of Topic.

Parameters:



30
31
32
33
34
35
36
37
# File 'lib/marko/model/topic.rb', line 30

def initialize(title, content, **)
  @parent = nil
  @items = []
  @title = title
  @content = content
   = 
  @markup = .delete(:markup)
end

Instance Attribute Details

#contentString (readonly)

Returns:



21
22
23
# File 'lib/marko/model/topic.rb', line 21

def content
  @content
end

#markupMarkup (readonly)

Returns:



25
26
27
# File 'lib/marko/model/topic.rb', line 25

def markup
  @markup
end

#metadataHash (readonly)

Returns:

  • (Hash)


23
24
25
# File 'lib/marko/model/topic.rb', line 23

def 
  
end

#titleString (readonly)

Returns:



19
20
21
# File 'lib/marko/model/topic.rb', line 19

def title
  @title
end

Instance Method Details

#add(item) ⇒ Object



52
53
54
55
56
# File 'lib/marko/model/topic.rb', line 52

def add(item)
  item.parent = self
  @items << item
  self
end

#delete(item) ⇒ Object



58
59
60
# File 'lib/marko/model/topic.rb', line 58

def delete(item)
  @items.delete(item)
end

#each(&block) ⇒ Object



45
46
47
48
49
50
# File 'lib/marko/model/topic.rb', line 45

def each(&block)
  super(&block)
  items.each do |e|
    e.each(&block)
  end
end

#find_by_id(ref) ⇒ Object



68
69
70
# File 'lib/marko/model/topic.rb', line 68

def find_by_id(ref)
  find{ it.id == ref } || root.find{ it.id == ref }
end

#idObject

sort of dynamic id



82
83
84
85
86
87
# File 'lib/marko/model/topic.rb', line 82

def id
  .fetch(:id, '').then do |e|
    e = parent.id + e if e.start_with?(?.) && parent
    e
  end
end

#id=(id) ⇒ Object



89
90
91
# File 'lib/marko/model/topic.rb', line 89

def id=(id)
  [:id] = id
end

Returns macro links in content.

Returns:

  • (Array<String>)

    macro links in content



63
64
65
66
# File 'lib/marko/model/topic.rb', line 63

def links
  return [] if @content.empty?
  @content.scan(/\[\[([\w\.]*)\]\]/).flatten.uniq
end

#lost_order_indexArray<String>

Returns ids in order_index but out of @items.

Returns:

  • (Array<String>)

    ids in order_index but out of @items



73
74
75
# File 'lib/marko/model/topic.rb', line 73

def lost_order_index
  order_index.reject{ item(it) }
end

#to_sObject



39
40
41
42
43
# File 'lib/marko/model/topic.rb', line 39

def to_s
  to_a
    .map{ "<#Topic id: #{it.id}, title: #{it.title}, level: #{it.nesting_level}>"}
    .join(?\n)
end