Class: Taskdown::Project

Inherits:
Object
  • Object
show all
Defined in:
lib/taskdown/project.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(string) ⇒ Project

Returns a new instance of Project.



6
7
8
9
# File 'lib/taskdown/project.rb', line 6

def initialize(string)
  @text = string
  @name = text.slice!(/^\!.+/)[1..-1].strip
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



4
5
6
# File 'lib/taskdown/project.rb', line 4

def name
  @name
end

#textObject (readonly)

Returns the value of attribute text.



4
5
6
# File 'lib/taskdown/project.rb', line 4

def text
  @text
end

Instance Method Details

#task_stringsObject



17
18
19
20
21
# File 'lib/taskdown/project.rb', line 17

def task_strings
  text.split(/(?=\n\w)/).delete_if do |element|
    element == "\n" || element == ""
  end.map(&:strip)
end

#tasksObject



11
12
13
14
15
# File 'lib/taskdown/project.rb', line 11

def tasks
  task_strings.map do |task|
    Taskdown::Task.new(task)
  end
end

#to_hashObject



23
24
25
26
# File 'lib/taskdown/project.rb', line 23

def to_hash
  { name: name,
    tasks: tasks.map(&:to_hash) }
end