Class: WunderMarkdown::Task

Inherits:
Struct
  • Object
show all
Defined in:
lib/wunder_markdown/task.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#childrenObject

Returns the value of attribute children.



3
4
5
# File 'lib/wunder_markdown/task.rb', line 3

def children
  @children
end

#clientObject

Returns the value of attribute client.



3
4
5
# File 'lib/wunder_markdown/task.rb', line 3

def client
  @client
end

#idObject

Returns the value of attribute id

Returns:

  • (Object)

    the current value of id



2
3
4
# File 'lib/wunder_markdown/task.rb', line 2

def id
  @id
end

#noteObject

Returns the value of attribute note

Returns:

  • (Object)

    the current value of note



2
3
4
# File 'lib/wunder_markdown/task.rb', line 2

def note
  @note
end

#parent_idObject

Returns the value of attribute parent_id

Returns:

  • (Object)

    the current value of parent_id



2
3
4
# File 'lib/wunder_markdown/task.rb', line 2

def parent_id
  @parent_id
end

#titleObject

Returns the value of attribute title

Returns:

  • (Object)

    the current value of title



2
3
4
# File 'lib/wunder_markdown/task.rb', line 2

def title
  @title
end

Instance Method Details

#root?Boolean

Returns:

  • (Boolean)


5
6
7
# File 'lib/wunder_markdown/task.rb', line 5

def root?
  parent_id.nil?
end

#to_markdownObject



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/wunder_markdown/task.rb', line 9

def to_markdown
  if root?
    markdown = "## #{title}  \n"
    if note && note != ''
      markdown += "  \n"
      note.chars.each_slice(80) do |slice|
        markdown += "> #{slice.join}\n"
      end
    end
    if children.any?
      markdown += "  \n"
      markdown += children.map(&:to_markdown).join("  \n")
    end
    markdown
  else
    "* #{title} \n"
  end
end