Class: Taskdown::Project
- Inherits:
-
Object
- Object
- Taskdown::Project
- Defined in:
- lib/taskdown/project.rb
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#text ⇒ Object
readonly
Returns the value of attribute text.
Instance Method Summary collapse
-
#initialize(string) ⇒ Project
constructor
A new instance of Project.
- #task_strings ⇒ Object
- #tasks ⇒ Object
- #to_hash ⇒ Object
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
#name ⇒ Object (readonly)
Returns the value of attribute name.
4 5 6 |
# File 'lib/taskdown/project.rb', line 4 def name @name end |
#text ⇒ Object (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_strings ⇒ Object
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 |
#tasks ⇒ Object
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_hash ⇒ Object
23 24 25 26 |
# File 'lib/taskdown/project.rb', line 23 def to_hash { name: name, tasks: tasks.map(&:to_hash) } end |