Class: WorkingClass::Parser
- Inherits:
-
Object
- Object
- WorkingClass::Parser
- Defined in:
- lib/working_class/parser.rb
Overview
The actual syntax parser
Instance Method Summary collapse
-
#initialize(string) ⇒ WorkingClass::Parser
constructor
Initializes a new Parser object with a given WorkingClass syntax string.
-
#to_h ⇒ Hash
Parses the syntax and returns an Hash with the result.
-
#to_tasklist ⇒ WorkingClass::Tasklist
Parses the syntax and returns a WorkingClass::Tasklist instance.
Constructor Details
#initialize(string) ⇒ WorkingClass::Parser
Initializes a new Parser object with a given WorkingClass syntax string
13 14 15 16 17 |
# File 'lib/working_class/parser.rb', line 13 def initialize(string) @raw_string = string @date_regex = /(?:\d{1,2}\.){2}\d{2,4}/ @time_regex = /\d{1,2}:\d{1,2}/ end |
Instance Method Details
#to_h ⇒ Hash
Parses the syntax and returns an Hash with the result
23 24 25 26 27 28 29 |
# File 'lib/working_class/parser.rb', line 23 def to_h { name: tasklist_name, tasks_count: tasks.length, tasks: tasks } end |
#to_tasklist ⇒ WorkingClass::Tasklist
Parses the syntax and returns a WorkingClass::Tasklist instance
35 36 37 38 39 40 41 42 43 |
# File 'lib/working_class/parser.rb', line 35 def to_tasklist tasks = Array.new raw = self.to_h raw[:tasks].each do |t| task = Task.new(t[:name], t) tasks << task end Tasklist.new raw[:name], tasks end |